"Only Shrink Larger Images" also modifies smaller images

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
inigomena

"Only Shrink Larger Images" also modifies smaller images

Post by inigomena »

Hi, I'd like to use the option to "Only Shrink Larger Images", but I find that it also modifies the smaller images, I guess it recompresses them without resizeing it. I think it should not alter the files if it is not necessary, is there a way to preserve the smaller images so they are not altered? If not, it would be a good improvement.
Last edited by inigomena on 2008-04-09T06:06:11-07:00, edited 1 time in total.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: "Only Shrink Larger Images" also modifies smaller images

Post by Bonzo »

http://www.imagemagick.org/script/comma ... php#resize

As you have not posted you code I am guessing you need to read the link above.
inigomena

Re: "Only Shrink Larger Images" also modifies smaller images

Post by inigomena »

I am using command line 'convert':
convert one.jpg -resize "640x480>" other.jpg

The source file is 624x396 and 68KB. The new file is 624x396 (OK) but it is 62KB. I don't want it to modify files unless it is necessary to resize them (I want to use it in a batch process for a lot of files, some of them will need to be resized but I don't want to modify the others).
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: "Only Shrink Larger Images" also modifies smaller images

Post by Bonzo »

I would think that is due to jpg compression; I do some tests with different -quality settings to see what happens.
inigomena

Re: "Only Shrink Larger Images" also modifies smaller images

Post by inigomena »

Yes, I think it loads the picture, checks whether it needs to resize it and then saves it again, recompressing in jpg format; if it has not needed to make changes, it would be better to leave the picture as it is, without saving it again.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: "Only Shrink Larger Images" also modifies smaller images

Post by Bonzo »

Yes I have just done a test:

original image = 13560
-quality 90 = 6784
-quality 60 = 3955
-quality 30 = 2842

Code: Select all

<?php
exec ("convert after.jpg -resize \"640x480>\" -quality 30 30.jpg");

exec ("convert after.jpg -resize \"640x480>\" -quality 60 60.jpg");

exec ("convert after.jpg -resize \"640x480>\" -quality 90 90.jpg");

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

Re: "Only Shrink Larger Images" also modifies smaller images

Post by fmw42 »

IM uses a default of 80 for jpg quality and will likely do what you are seeing, rewrite the output. I suspect you will need to write a script to test the dimensions of the image and then process it if it is large enough and skip the resize command line if small enough.

You can try posting to the Bugs forum and see what they say.
Post Reply