本文整理汇总了PHP中resource::setImageCompressionQuality方法的典型用法代码示例。如果您正苦于以下问题:PHP resource::setImageCompressionQuality方法的具体用法?PHP resource::setImageCompressionQuality怎么用?PHP resource::setImageCompressionQuality使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类resource
的用法示例。
在下文中一共展示了resource::setImageCompressionQuality方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
/**
* 保存图像
* @param string $imgname 图像保存名称
* @param string $type 图像类型
* @param integer $quality JPEG图像质量
* @param boolean $interlace 是否对JPEG类型图像设置隔行扫描
*/
public function save($imgname, $type = null, $quality = 80, $interlace = true)
{
if (empty($this->img)) {
E('没有可以被保存的图像资源');
}
//设置图片类型
if (is_null($type)) {
$type = $this->info['type'];
} else {
$type = strtolower($type);
$this->img->setImageFormat($type);
}
//JPEG图像设置隔行扫描
if ('jpeg' == $type || 'jpg' == $type) {
$this->img->setImageInterlaceScheme(1);
}
// 设置图像质量
$this->img->setImageCompressionQuality($quality);
//去除图像配置信息
$this->img->stripImage();
//保存图像
$imgname = realpath(dirname($imgname)) . '/' . basename($imgname);
//强制绝对路径
if ('gif' == $type) {
$this->img->writeImages($imgname, true);
} else {
$this->img->writeImage($imgname);
}
}
示例2: resize
/**
* 缩略(放大)图片
* @param int $thumbWidth 缩放的最大宽度
* @param int $thumbHeight 缩放的最大高度
* @param bool $magnify 是否允许放大图片
* @return bool 成功返回true,失败返回false
*/
public function resize($thumbWidth = 0, $thumbHeight = 0, $magnify = true)
{
$width = $this->getWidth();
$height = $this->getHeight();
do {
//定宽缩放
if ($thumbHeight === 0) {
$thumbHeight = $thumbWidth / $width * $height;
break;
}
//定高缩放
if ($thumbWidth === 0) {
$thumbWidth = $thumbHeight / $height * $width;
break;
}
//等比例缩放
if ($width / $thumbWidth > $height / $thumbHeight) {
$ratio = $thumbWidth / $width;
} else {
$ratio = $thumbHeight / $height;
}
$thumbWidth = $width * $ratio;
$thumbHeight = $height * $ratio;
} while (0);
//由于图片是等比率的,所以只需判断一条边
if (!$magnify && $thumbWidth >= $width) {
return true;
}
self::$resource->setImageCompressionQuality(90);
//1-100值越大,越清晰
return self::$resource->scaleImage($thumbWidth, $thumbHeight);
}
示例3: write
/**
* {@inheritdoc}
*/
public function write($file, $jpeg_quality = null)
{
if ($jpeg_quality) {
$this->resource->setImageCompression(Imagick::COMPRESSION_JPEG);
$this->resource->setImageCompressionQuality($jpeg_quality);
}
return $this->resource->writeImages($file, true);
}
示例4: imagickImage
/**
* Output imagick image to file
*
* @param resource $img imagick image resource
* @param string $filename The path to save the file to.
* @param string $destformat The Image type to use for $filename
* @param int $jpgQuality JEPG quality (1-100)
* @return bool
*/
protected function imagickImage($img, $filename, $destformat, $jpgQuality = null)
{
if (!$jpgQuality) {
$jpgQuality = $this->options['jpgQuality'];
}
try {
if ($destformat) {
if ($destformat === 'gif') {
$img->setImageFormat('gif');
} else {
if ($destformat === 'png') {
$img->setImageFormat('png');
} else {
if ($destformat === 'jpg') {
$img->setImageFormat('jpeg');
}
}
}
}
if (strtoupper($img->getImageFormat()) === 'JPEG') {
$img->setImageCompression(imagick::COMPRESSION_JPEG);
$img->setImageCompressionQuality($jpgQuality);
try {
$orientation = $img->getImageOrientation();
} catch (ImagickException $e) {
$orientation = 0;
}
$img->stripImage();
if ($orientation) {
$img->setImageOrientation($orientation);
}
}
$result = $img->writeImage($filename);
} catch (Exception $e) {
$result = false;
}
return $result;
}