Page 1 of 1

MagickSetImageCompressionQuality seems broken in 6.5.2

Posted: 2009-05-05T01:10:55-07:00
by fflewddur
Hi,

I've recently ported an application that used the ImageMagick command-line tools to instead access the MagickWand API directly. Everything seems to be working well, except that the file size of the resulting JPEG images is considerably higher than when I was using the command-line tools. From some trouble-shooting, it seems that the call to MagickSetImageCompressionQuality() doesn't actually do anything--no matter what values I pass for 'quality', the resulting file size is the same. In case it's helpful, here is the order of the MagickWand API calls I'm using:

Code: Select all

	wand = NewMagickWand ();
	if (MagickReadImageBlob (wand, image, image_size)) {
// I cut out the non-IM stuff

			if (!MagickCropImage (wand, width_cropped, height_cropped, x_offset, y_offset)) {
				g_warning ("Couldn't crop image");
			}
			MagickResetImagePage(wand, NULL);

			if (!MagickResizeImage (wand, width_scaled, height_scaled, SincFilter, 1)) {
				g_warning ("Couldn't resize image");
			}
			MagickResetImagePage(wand, NULL);
			
			MagickCropImage (wand, THUMB_WIDTH, THUMB_HEIGHT, x_offset, y_offset);
			MagickNormalizeImage (wand);
			MagickEnhanceImage (wand);
			MagickSigmoidalContrastImage (wand, MagickTrue, 3.0, 60.0);
			
			if (!MagickSetImageFormat (wand, "JPEG")) {
				g_warning ("Couldn't set format to JPEG");
			}
			if (!MagickSetCompression (wand, JPEGCompression)) {
				g_warning ("Couldn't set compression type");
			}
			if (!MagickSetCompressionQuality (wand, THUMB_QUALITY)) {
				g_warning ("Couldn't set quality to %d", THUMB_QUALITY);
			}

			MagickStripImage (wand);
			
			blob = MagickGetImageBlob (wand, &blob_size);
			// Save the blob to glib-allocated memory
			// so we can write all of the images to disk at once, later.
			*thumbnail = g_new0 (gchar, blob_size);
			memcpy (*thumbnail, blob, blob_size);
			*thumbnail_size = blob_size;
			MagickRelinquishMemory (blob);
		}
	}
	DestroyMagickWand (wand);
Any ideas? My only thought at the moment is that maybe there's something in the MagickGetImageBlob() code that isn't taking the quality setting into account.

Re: MagickSetImageCompressionQuality seems broken in 6.5.2

Posted: 2009-05-05T05:45:25-07:00
by magick
Your code says MagickSetCompressionQuality(). What you need is MagickSetImageCompressionQuality().

Re: MagickSetImageCompressionQuality seems broken in 6.5.2

Posted: 2009-05-05T09:41:30-07:00
by fflewddur
*smacks forehead*

Thanks! :)