PHP Png在调整大小后具有黑色背景
当我尝试调整PNG的大小时 与PHP Png在调整大小后具有黑色背景,php,png,transparency,transparent,alphablending,Php,Png,Transparency,Transparent,Alphablending,当我尝试调整PNG的大小时 与 然后,调整大小后的图像背景是黑色的,我已经尝试了一些不同的解决方案,但还没有成功 不要使用$transparent=…试试这个:imagecolorpransible($new_-image,imagecoloralallocatealpha($new_-image,0,0,127))我能够解决这个问题:没有设置$image_类型,因此每个重铸的图像都是jpeg function resize($width,$height){ $new_image
然后,调整大小后的图像背景是黑色的,我已经尝试了一些不同的解决方案,但还没有成功 不要使用
$transparent=…
试试这个:imagecolorpransible($new_-image,imagecoloralallocatealpha($new_-image,0,0,127))代码>我能够解决这个问题:没有设置$image_类型,因此每个重铸的图像都是jpeg
function resize($width,$height){
$new_image = imagecreatetruecolor($width, $height);
if($this->image_type == IMAGETYPE_PNG || $this->type == 'image/png')
{
imagealphablending($new_image, false);
imagesavealpha($new_image,true);
$transparent = imagecolorallocatealpha($new_image, 255, 255, 255, 127);
imagefilledrectangle($new_image, 0, 0, $width, $height, $transparent);
}
imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
$this->image = $new_image;
}
function output($image_type=IMAGETYPE_JPEG, $compression=100){
if($image_type == IMAGETYPE_JPEG){
imagejpeg($this->image, null, $compression);
}elseif($image_type == IMAGETYPE_GIF){
imagegif($this->image);
}elseif($image_type == IMAGETYPE_PNG){
imagepng($this->image);
}
}