哈希空间 Ctrl + F 进行搜索
首页 php手册中文版 CSS中文手册 哈希文档 Markdown在线工具

Imagick::setCompressionQuality

(PECL imagick 2, PECL imagick 3)

Imagick::setCompressionQualitySets the object's default compression quality

说明

public Imagick::setCompressionQuality(int $quality): bool

Sets the object's default compression quality.

警告

This method only works for new images e.g. those created through Imagick::newPseudoImage. For existing images you should use Imagick::setImageCompressionQuality().

参数

quality

An int between 1 and 100, 1 = high compression, 100 low compression.

返回值

成功时返回 true

范例

示例 #1 Imagick::setCompressionQuality()

<?php
function setCompressionQuality($imagePath$quality) {

    
$backgroundImagick = new \Imagick(realpath($imagePath));
    
$imagick = new \Imagick();
    
$imagick->setCompressionQuality($quality);
    
$imagick->newPseudoImage(
        
$backgroundImagick->getImageWidth(),
        
$backgroundImagick->getImageHeight(),
        
'canvas:white'
    
);

    
$imagick->compositeImage(
        
$backgroundImagick,
        \
Imagick::COMPOSITE_ATOP,
        
0,
        
0
    
);
    
    
$imagick->setFormat("jpg");    
    
header("Content-Type: image/jpg");
    echo 
$imagick->getImageBlob();
}

?>
打开 哈希空间 微信小程序中查看更佳