Page 1 of 1

Resize image to specified size (kb)

Posted: 2014-06-23T14:15:59-07:00
by myspacee
Hello,
i've a PHP mail module and want to send an image as attachment. No problem for this.

Want to limit attachment to 512 kb. Is there any way to convert an image with IM command ?
I know that I can script PHP to check size every conversion, but ask if exist any existing way to use IM natively.

thank you for any info,
m.

Re: Resize image to specified size (kb)

Posted: 2014-06-23T14:32:11-07:00
by fmw42
If you convert the file to jpg, you can set the file size as per http://www.imagemagick.org/Usage/formats/#jpg

Code: Select all

convert image -define jpeg:extent=512kb newimage.jpg

If on Linux, Mac OS or Windows with Cygwin, I have a script called downsize that you could try that is not restricted to jpg

Re: Resize image to specified size (kb)

Posted: 2014-06-24T08:41:32-07:00
by myspacee
thank you for reply,
reading around I find RIOT : http://luci.criosweb.ro/riot/

But IM is my choice for PHP integration.

Thank you again for help,
m.

Re: Resize image to specified size (kb)

Posted: 2015-12-02T10:24:53-07:00
by bair.sa
Can the same limitation to the file size (kb) be made to a .tga file?

convert image -define jpeg:extent=512kb newimage.jpg

Re: Resize image to specified size (kb)

Posted: 2015-12-02T11:24:49-07:00
by bair.sa
bair.sa wrote:Can the same limitation to the file size (kb) be made to a .tga file?

convert image -define jpeg:extent=512kb newimage.jpg
i tried changing the jpeg above to tga and the ending extension to .tga but it does not work.

Re: Resize image to specified size (kb)

Posted: 2015-12-02T12:24:49-07:00
by Bonzo
A list of the formats with their define options: http://www.imagemagick.org/script/comma ... php#define
tga does not seem to be on the list.

Re: Resize image to specified size (kb)

Posted: 2015-12-02T15:04:10-07:00
by fmw42
The size limitation is currently only for JPEG as the define name implies. But if on Linux, Mac OSX or Windows with Cygwin, you can do that with my script, downsize, at the link below. It does not care about image format.

Re: Resize image to specified size (kb)

Posted: 2016-02-02T04:09:05-07:00
by Nemo_bis
fmw42 wrote:The size limitation is currently only for JPEG as the define name implies. But if on Linux, Mac OSX or Windows with Cygwin, you can do that with my script, downsize, at the link below. It does not care about image format.
I had some issues with this helpful suggestion. Moved to viewtopic.php?f=1&t=29093