Incorrect quality factor returned by Image::formatExpression after quality change
Swiss army knife of image processing
Brought to you by:
bfriesen
Hello
I've discovered that the Image::formatExpression method returnes invalid quality factor if the quality is changed before calling this method.
Look at this sniplet:
Image image; try { image.read(argv[1]); cout << "Input quality: " << image.formatExpression("%Q%%") << endl; cout << "Setting quality: 66%" << endl; image.quality(66); cout << "Reading quality: " << image.quality() << "%" << endl; image.write("/tmp/tmp.jpg"); cout << "Output quality: " << image.formatExpression("%Q%%") << endl; } catch (Exception &e) { cout << e.what(); }
and it's output:
Input quality: 94% Setting quality: 66% Reading quality: 66% Output quality: 94%
I would suspect that the reported "Output quality" will be set to 66% as, for exapmple magick (%m) does, if changed.
--
Best Regards
Przemysław Sobala
Rather oddly, the GraphicsMagick Image structure does not store 'quality' and so quality is only stored in an ImageInfo structure used while writing the image (this attribute will eventually be added). After some investigation, I see if the attribute 'JPEG-Quality' is defined, then the value of this attibute takes precedence over the value stored in ImageInfo. The 'JPEG-Quality' attribute became defined when the JPEG file was first read. This attribute is peculiar to JPEG.
The attribute may be deleted via
image.attribute("JPEG-Quality", NULL);
and then the value which was set should appear again in formatExpression().