output file with specified filesize + original geometry?

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
cybersd
Posts: 3
Joined: 2012-03-19T07:45:25-07:00
Authentication code: 8675308

output file with specified filesize + original geometry?

Post by cybersd »

I have pictures between 3 and 30 MB. All this pictures must be convert to the same output filesize 2MB but with the original geometry size.
I try this with -quality, resize etc., but I get different output filesizes or samler geometry.

I need help.....
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: output file with specified filesize + original geometry?

Post by fmw42 »

What format are your output images? What platform are you using?

Basically, other than your playing with -quality, there is no way to keep the image dimensions the same and get a specific file size as far a I know in IM.
cybersd
Posts: 3
Joined: 2012-03-19T07:45:25-07:00
Authentication code: 8675308

Re: output file with specified filesize + original geometry?

Post by cybersd »

The Source image file is jpg and the Output file jpg, too.
I use an Linux System (debian, Suse).
I also make Tests with -quality, but the output size e.g. from a 8 MB file is sometimes 2,3 MB and sometimes 5 MB, with the Same quality Percent size.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: output file with specified filesize + original geometry?

Post by fmw42 »

As I said you have to use trial an error to get the specified file size by changing -quality as the compression will be image dependent. There is no simple recipe to get a specified file size via -quality in IM.

I am not sure how PS does jpg compression to a given file size for web output.

The only way I know to do it is to iterate on the -quality until you get what you want for the filesize.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: output file with specified filesize + original geometry?

Post by anthony »

ImageMagick JPG coder can do that 'trial and error' for you.

See IM Examples, Common image file Formats, JPEG, Writing options
and specifically the -define jpeg:extent={size} option
http://www.imagemagick.org/Usage/formats/#jpg_write
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: output file with specified filesize + original geometry?

Post by fmw42 »

I stand corrected. Neat. I learned something new today.
cybersd
Posts: 3
Joined: 2012-03-19T07:45:25-07:00
Authentication code: 8675308

Re: output file with specified filesize + original geometry?

Post by cybersd »

Thank you! It works fine!
Post Reply