问题
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);
回答1:
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.
来源:https://stackoverflow.com/questions/46441364/what-is-difference-between-setimagecompressionquality-vs-setcompressionquality