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);