本文整理匯總了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;
}