Resize image to specified size (kb)

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
myspacee
Posts: 153
Joined: 2007-06-14T02:09:35-07:00

Resize image to specified size (kb)

Post by myspacee » 2014-06-23T14:15:59-07:00

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.

User avatar
fmw42
Posts: 25266
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resize image to specified size (kb)

Post by fmw42 » 2014-06-23T14:32:11-07:00

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

myspacee
Posts: 153
Joined: 2007-06-14T02:09:35-07:00

Re: Resize image to specified size (kb)

Post by myspacee » 2014-06-24T08:41:32-07:00

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.

bair.sa
Posts: 2
Joined: 2015-12-02T10:22:45-07:00
Authentication code: 1151

Re: Resize image to specified size (kb)

Post by bair.sa » 2015-12-02T10:24:53-07:00

Can the same limitation to the file size (kb) be made to a .tga file?

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

bair.sa
Posts: 2
Joined: 2015-12-02T10:22:45-07:00
Authentication code: 1151

Re: Resize image to specified size (kb)

Post by bair.sa » 2015-12-02T11:24:49-07:00

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.

Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Resize image to specified size (kb)

Post by Bonzo » 2015-12-02T12:24:49-07:00

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.

User avatar
fmw42
Posts: 25266
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resize image to specified size (kb)

Post by fmw42 » 2015-12-02T15:04:10-07:00

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.

Nemo_bis
Posts: 11
Joined: 2012-06-16T01:13:18-07:00
Authentication code: 13

Re: Resize image to specified size (kb)

Post by Nemo_bis » 2016-02-02T04:09:05-07:00

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

Post Reply