resized (smaller) image files larger than original?

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
morticus
Posts: 3
Joined: 2013-01-29T01:31:03-07:00
Authentication code: 6789

resized (smaller) image files larger than original?

Post by morticus »

Hi

i've searched all over the place but can't seem to find a definitive answer, and i'm sorry, but i'm a real beginner. I'm using stockboxphoto as an online photo gallery. it sends commands to imagemagick for resizing the original (large, high quality) file into various smaller file options for purchase.

the command line it uses for resize is:

{$convert_path}convert -units PixelsPerInch -density {$ppi} "{$path_i}{$file_i}" -resize {$w_size}x{$h_size} -quality {$quality} "{$path_o}{$file_o}"

we have limited access, but are able to fill these options i.e. density, pixel x pixel, quality via the third party interface.

most of the time it works fine, but sometimes the resized file size is larger than the original. e.g. original file: 2706 pixels x 2926 pixels, file size 4.73 MB (shot with a high end Canon EOS-1D X)

when resized using command line: convert -units PPI -density 300 "in file path" -resize 2560 x 2560 -quality 100 "out file path"

the result is 2368 x 2560 pixels, file size 5.21 MB

why is the new file larger in MB than the original, but has fewer pixels?

the developers don't seem to be able to help me in this instance so i'm hoping someone here can.

we are running IM version 6.6.0.4. on a Linux server setup.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: resized (smaller) image files larger than original?

Post by snibgo »

If the input and output images are the same format, and not compressed, and the same bit depth, smaller numbers of pixels will take fewer megabytes.

If input and output are both JPG and input quality is less than 100, the resize will interpolate pixels, creating new colours. Saving at quality 100 will try to keep most of them. Try leaving off the quality setting.

For other formats (such as TIFF and PNG), the input might be 8 bits/pixel/channel, but the interpolation is best represented in 16 bits/pixel/channel.
snibgo's IM pages: im.snibgo.com
morticus
Posts: 3
Joined: 2013-01-29T01:31:03-07:00
Authentication code: 6789

Re: resized (smaller) image files larger than original?

Post by morticus »

thanks heaps.

the input and output files are both jpg.. thought that might be the case re: adding info by interpolation... but how do i figure out what 'quality' my input image is? i don't want to degrade a high quality image by setting the compression quality too low.... and i would've thought an image from a high end canon would be high quality?

i understand the default quality for IM is 92? we can't leave off the quality (i've only access via a third party gallery software stockbox photo), but i can input different qualities...

also, when i trialled it without the quality feature (they added it recently), i generally got much smaller file sizes than when using photoshop... which is why i put the quality setting up to 100 once they added it.

one other thing i've noticed in the command line.. it has a spelling mistake for 'quality' would this matter? see below {quanlity} instead of {quality}

{$convert_path}convert -units PixelsPerInch -density {$ppi} "{$path_i}{$file_i}" -resize {$w_size}x{$h_size} -quality {$quanlity} "{$path_o}{$file_o}"
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: resized (smaller) image files larger than original?

Post by fmw42 »

IM tries to use the same input quality for its output if available; otherwise 92. You can find the input quality via

identify -verbose image.jpg

Note that quality means something different for png files than it does for jpg

see
http://www.imagemagick.org/script/comma ... hp#quality
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: resized (smaller) image files larger than original?

Post by snibgo »

Code: Select all

identify -verbose x.jpg
or

Code: Select all

identify -format "%Q" x.jpg
Never forget that reading then writing a jpeg will reduce its quality, so an image saved at 80 then read and saved as 80 again, will look worse after the second save. Also, the algorithm used by IM may differ from that used in the camera, so the numbers may not mean eactly the same thing.

{$quanlity} is a script variable, just like {$w_size}. Provided it is always spelt that way, no problem.
snibgo's IM pages: im.snibgo.com
morticus
Posts: 3
Joined: 2013-01-29T01:31:03-07:00
Authentication code: 6789

Re: resized (smaller) image files larger than original?

Post by morticus »

thank you so much. got the -verbose command working and it's very useful.

i've found where the third party software have stored the command line to imagemagick (-convert -resize etc command as described above) and am considering removing the -quality variable. i understand that IM will try and 'read' the quality of the input file (jpg) and match it for the output file (jpg). If it can't 'read' it, then it will use 92 as the default quality for the convert.

when does IM have difficulty reading the quality of input files if all input files are jpgs? just thinking that if it reverts to it's default quality (92) all the time, then it's going to result in quite a degradation of quality and file size which i don't want.

many many thanks!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: resized (smaller) image files larger than original?

Post by snibgo »

If this is the only re-save you are doing, it shouldn't harm the visual quality much. If you are doing multiple changes and saving as jpeg each time, then you shouldn't. Instead, use a lossless compression for intermediate files.

IM can't get a jpeg quality setting from non-jpeg files. I don't know if it can always get it from jpegs.
snibgo's IM pages: im.snibgo.com
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: resized (smaller) image files larger than original?

Post by anthony »

Jpeg quality is typically only a guess, and is variable depending on the japg library used originally.

Also the main reason a filesize will get bigger (when not a quality setting problem) is compression.
resize generates extra colors as it tried to generate a 'good' resize, that makes the compressions change.

Even PNG will generate different image file sizes, for the same input image, depending on the selection of compression algorithm. That was why a program called "pngcrush" was created. It will compress a given PNG in many different ways, to determine whcih method generates the best compression for the given image.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply