问题描述
我在Imagick中发现了两种设置图像压缩质量的方法
I found two methods in Imagick for set image compression quality
A)setImageCompressionQuality
A ) setImageCompressionQuality
B)setCompressionQuality
B ) setCompressionQuality
所以我想知道哪种情况最好,为什么在这样的情况下
so I want to know which one is best and why in below condition
我了解到setCompressionQuality
方法仅适用于新图像(?)
I read that setCompressionQuality
method only works for new images (?)
我正在尝试压缩jpeg/png文件
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);
推荐答案
方法setImageCompressionQuality
设置当前图像的压缩质量.此方法是MagickWand
的MagickSetImageCompressionQuality
函数的包装. 源代码为:
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);
}
方法setCompressionQuality
设置整个对象的压缩质量.此方法是MagickWand
的MagickSetCompressionQuality
函数的包装. 源代码是:
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);
}
MagickWand
结构包含Image
和ImageInfo
结构的实例,来源:
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 */
...
};
Image
和ImageInfo
结构包含一个size_t quality;
数据成员.因此,对于您的示例,setImageCompressionQuality
很好.
Both Image
and ImageInfo
structs hold a size_t quality;
data member. So for your example setImageCompressionQuality
is perfectly fine.
这篇关于setImageCompressionQuality与setCompressionQuality之间有什么区别-Imagick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!