Page 1 of 1

Why image filesize changes after writing to Blob?

Posted: 2013-02-20T00:06:16-07:00
by vladimir_ff
I have an image https://dl.dropbox.com/u/79309031/image.jpg
The size of file is 1650 bytes.
My code:

Code: Select all

Image newimage( "image.jpg" );
cout << newimage.fileSize() << endl;
Blob blob1;
newimage.write(&blob1);
cout << newimage.fileSize() << endl;
And the output is:
1650
1653
What happened?
Why filesize has changed after writing to blob?
IM 6.7.6.9
Ubuntu 11.04

Re: Why image filesize changes after writing to Blob?

Posted: 2013-04-04T18:49:10-07:00
by anthony
JPG like most image file formats have a dynamic compression algorthim.

That means the file size depends on so many factors it is next to imposible to guarentte its size is predictable.

Image changes, meta-data changes, version of IM, version of coder, version of library, quality, colorspace, etc etc etc all will likely change a images file size.

A 3 byte difference on a read-write loop... I'd say you were lucky it wasn't bigger (or smaller)!


JPEG especially is a lossy compression... every time you write it the image gets modified. as such it ALWAYS changes on every read-write cycle as every time you do read and write JPG the image degrades a bit more.

JPEG should never be used for you main image storage, especially your source image, and for intermediate image processing work. It should only be used for final image, due to its small size.

See IM Examples, JPEG, Compression
http://www.imagemagick.org/Usage/formats/#jpg

Actually I seem to need to mention this on just about EVERY Im Examples page!

In summery, don't use JPEG unless you really need to.