PHP-GD:保留半透明区域
发布时间:2020-12-13 22:33:58 所属栏目:PHP教程 来源:网络整理
导读:我需要 PHP站点的通用图像上传.照片和徽标应该在一定程度上重新调整大小,以确保它们不会太大并且符合设计. 我正在尝试使用此代码: function resize($width,$height) { $new_image = imagecreatetruecolor($width,$height); if($this-image_type == PNG or $
我需要
PHP站点的通用图像上传.照片和徽标应该在一定程度上重新调整大小,以确保它们不会太大并且符合设计.
我正在尝试使用此代码: function resize($width,$height) { $new_image = imagecreatetruecolor($width,$height); if($this->image_type == PNG or $this->image_type == GIF) { imagealphablending($new_image,false); imagesavealpha($new_image,true); $transparent = imagecolorallocatealpha($new_image,255,127); imagefilledrectangle($new_image,$nWidth,$nHeight,$transparent); } imagecopyresized($new_image,$this->image,$width,$height,$this->getWidth(),$this->getHeight()); $this->image = $new_image; } 但是,当我上传的图像区域的alpha值介于0到255之间时,它们会被完整的黑色替换,将抗锯齿区域变为黑色边框. 完全透明度适用于PNG和GIF,只有半透明区域是个问题. 如果我没有使用正确的术语来解释我的问题,我很抱歉,也许这就是为什么我几乎找不到任何东西. 解决方法
尝试:
function resize($width,$height); if($this->image_type == PNG or $this->image_type == GIF) { imagefill($new_image,IMG_COLOR_TRANSPARENT); imagesavealpha($new_image,true); imagealphablending($new_image,true); } imagecopyresampled($new_image,$this->getHeight()); $this->image = $new_image; } 基于this(我知道它的工作原理). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |