MagickSetImageCompressionQuality seems broken in 6.5.2

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
fflewddur

MagickSetImageCompressionQuality seems broken in 6.5.2

Post 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.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: MagickSetImageCompressionQuality seems broken in 6.5.2

Post by magick »

Your code says MagickSetCompressionQuality(). What you need is MagickSetImageCompressionQuality().
fflewddur

Re: MagickSetImageCompressionQuality seems broken in 6.5.2

Post by fflewddur »

*smacks forehead*

Thanks! :)
Post Reply