setImageCompressionQuality

setImageCompressionQuality

本文介绍了setImageCompressionQuality与setCompressionQuality之间有什么区别-Imagick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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设置当前图像的压缩质量.此方法是MagickWandMagickSetImageCompressionQuality函数的包装. 源代码为:

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设置整个对象的压缩质量.此方法是MagickWandMagickSetCompressionQuality函数的包装. 源代码是:

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结构包含ImageImageInfo结构的实例,来源:

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 */
  ...
};

ImageImageInfo 结构包含一个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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-29 20:34