Page 1 of 1

New image size is larger than old after stripping/cropping

Posted: 2008-02-20T16:31:38-07:00
by imagewinter
Using the convert command.

Sometimes, when I -strip the image metadata, the new image size is larger than the old! How and why is that?

Rarely, when I -crop an image, say by 25 pixels, the new image size is larger than the old! How and why is that?

Regarding the above, no additional switches were used. This means the -quality stayed the same, etc.

Re: New image size is larger than old after stripping/cropping

Posted: 2008-02-20T18:19:03-07:00
by fmw42
You have not said what type of image you are using. If jpg, then the issue is the amount of compression that IM is applying after stripping the metadata compared to what you had before. Also remember that IM makes 3 channels for you images, I think, even if it is grayscale.

Re: New image size is larger than old after stripping/cropping

Posted: 2008-02-20T22:23:06-07:00
by anthony
Depends on the coder for a special image format on if IM saves a image as RGB or grayscale. Often it will product a grayscale image file if the format can handle it and the image has no non-grayscale colors.

Sometimes forcing a RGB file image format for a grayscale image can be difficult. :-)

Best idea for that is test it and see.

NOTE the Quality for the original JPEG image is often a guess on IM's part, as there no real collelation on quality to image size between the various JPEG librarys used. Photoshop jpeg quality can be different to the libjpeg (which IM uses), or even the jpeg DLL on windows.

Re: New image size is larger than old after stripping/cropping

Posted: 2008-02-21T07:48:31-07:00
by imagewinter
Yes, JPG.

So it is the extra channels that are increasing the size? If so, how do I prevent it from increasing the size when stripping or cropping?

Often, I discard useless stuff such as metadata and thick borders. So there is a minor change. But the increase in size is ironic. How do I go about discarding these useless stuff and at the same time save a few kilobytes?

Few kilobytes here, and few there, it all adds up to megabytes at the end. Also, load time would be slightly better too.

Re: New image size is larger than old after stripping/cropping

Posted: 2008-02-21T11:18:13-07:00
by fmw42
If you are keeping the image as jpg after -strip, then the issue is what quality level IM is applying automatically when it generates your output jpg. JPG is a lossy compression storage format. If you want a smaller file size, then you need to add -quality to your command line. To find out what you are starting with, use

identify -verbose info: <image.jpg>

and look in the printout for the line that starts with Quality.

Then use that value with -qualit in your command line (or something a bit smaller). The problem is that different tools may use the same quality value, but get slightly different compression results.

Re: New image size is larger than old after stripping/cropping

Posted: 2008-02-21T15:35:12-07:00
by imagewinter
Lowering the quality would of course reduce the size. But I asked:
How do I prevent it from increasing the size when stripping or cropping?
How do I go about discarding these useless stuff and at the same time save a few kilobytes?
When it comes to pictures. The least thing to sacrifice would be quality.

Theoretically, stripping the metadata or cropping a border should reduce the size. But this is not always the case.

So I was wondering if there is anything more I can do to the above. Or additional thing I can remove in the images that would reduce the size.

Re: New image size is larger than old after stripping/cropping

Posted: 2008-02-21T17:10:19-07:00
by fmw42
I think you are missing my point. I suspect IM is changing the amount of compression on your image so that sometimes it ends up with higher quality and lower compression, even when you take away the metadata and some border. The only thing you can do that I know of is to change the quality setting to get a desired (equal or lower) size, which may or may not maintain the visual quality you had to start. I know of no other data that you can discard.

Re: New image size is larger than old after stripping/cropping

Posted: 2008-02-21T19:01:07-07:00
by anthony
You can preserve the JPEG image data, without loss through the use of a read/write cycle, by using a loss-less JPEG processing program. On such program is "jhead".

IM is designed to modify images, and so it will always to a read/write cycle on JPEG images. It also tries to make a 'guess' at the quality for the JPEG image, but that is only a guess as the actual quality setting used is not recorded in the JPEG image. It can be rather meaningless between different JPEG library in any case.

If you modify the image, use IM, if you just want to strip meta-data and not change the image, use some other program. I guarantee it will be smaller, and the image will not have degraded by a read/write cycle.

See IM Examples, Common Image File Formats, JPEG
http://imagemagick.org/Usage/formats/#jpg