Issue
I found two methods in Imagick for set image compression quality
A ) setImageCompressionQuality
B ) setCompressionQuality
so I want to know which one is best and why in below condition
I read that setCompressionQuality method only works for new images (?)
I am trying to compress a file jpeg/png
$im = new Imagick();
$im->readImage($file); // path/to/file
$im->setImageCompressionQuality($quality); // 90,80,70 e.g.
$im->writeImage($file);
Solution
The method setImageCompressionQuality sets compression quality for your current image. This method is a wrapper for MagickWand's MagickSetImageCompressionQuality function. Source code is:
WandExport MagickBooleanType MagickSetImageCompressionQuality(MagickWand *wand,
const size_t quality)
{
assert(wand != (MagickWand *) NULL);
assert(wand->signature == MagickWandSignature);
if (wand->debug != MagickFalse)
(void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
if (wand->images == (Image *) NULL)
ThrowWandException(WandError,"ContainsNoImages",wand->name);
//This line sets the quality for the instance 'images'
wand->images->quality=quality;
return(MagickTrue);
}
The method setCompressionQuality sets compression quality for the whole object. This method is a wrapper for MagickWand's MagickSetCompressionQuality function. Source code is:
WandExport MagickBooleanType MagickSetCompressionQuality(MagickWand *wand,
const size_t quality)
{
assert(wand != (MagickWand *) NULL);
assert(wand->signature == MagickWandSignature);
if (wand->debug != MagickFalse)
(void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
//This line sets quality for the image_info struct instance.
wand->image_info->quality=quality;
return(MagickTrue);
}
The MagickWand struct holds instances of Image and ImageInfo structs, source:
struct _MagickWand
{
...
Image
*images; /* The images in this wand - also the current image */
ImageInfo
*image_info; /* Global settings used for images in Wand */
...
};
Both Image and ImageInfo structs hold a size_t quality; data member. So for your example setImageCompressionQuality is perfectly fine.
Answered By - zindarod Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.