如何在PHP中以透明的方式调整pngs的大小?
我正在尝试在PHP中使用透明背景调整png的大小,但我在网上找到的代码示例不适合我。这是我正在使用的代码,建议将不胜感激!
$this->image = imagecreatefrompng($filename);
imagesavealpha($this->image, true);
$newImage = imagecreatetruecolor($width, $height);
// Make a new transparent image and turn off alpha blending to keep the alpha channel
$background = imagecolorallocatealpha($newImage, 255, 255, 255, 127);
imagecolortransparent($newImage, $background);
imagealphablending($newImage, false);
imagesavealpha($newImage, true);
imagecopyresampled($newImage, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
$this->image = $newImage;
imagepng($this->image,$filename);
更新通过“不起作用”,我的意思是说当我调整pngs大小时,背景颜色会变为黑色。