Skip to content
This repository has been archived by the owner on Jan 4, 2020. It is now read-only.

Gd.class.php保存png图片在图片质量处理上有错误 #507

Open
Jack-YanTC opened this issue Sep 9, 2017 · 0 comments
Open

Gd.class.php保存png图片在图片质量处理上有错误 #507

Jack-YanTC opened this issue Sep 9, 2017 · 0 comments

Comments

@Jack-YanTC
Copy link

Jack-YanTC commented Sep 9, 2017

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);
}
//保存图像
if ('jpeg' == $type || 'jpg' == $type) {
//JPEG图像设置隔行扫描
imageinterlace($this->img, $interlace);
imagejpeg($this->img, $imgname, $quality);
} elseif ('gif' == $type && !empty($this->gif)) {
$this->gif->save($imgname);
} elseif ('png' == $type) {
//设定保存完整的 alpha 通道信息
imagesavealpha($this->img, true);
//ImagePNG生成图像的质量范围从0到9的
imagepng($this->img, $imgname, $quality / 10);

} else {
$fun = 'image' . $type;
$fun($this->img, $imgname);
}
}

因为图片质量传100的时候,png的质量就是10了,此时将正常无法保存png图片
解决办法:可将上面字体加粗的地方可改为
imagepng($this->img, $imgname, ($quality-10) / 10)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant