PHP GD:imagecopy()无法正常工作

时间:2018-06-24 16:18:11

标签: php transparency gd

嗨,我有一个绘图图像列表,我只想从它们中获取具有透明背景的绘图...

当前链接到我的图像: Output Image / Input Image

<?php
$path = 'images/test1.png';

$input = imagecreatefrompng($path);
$width = imagesx($input);
$height = imagesy($input);

$output = imagecreatetruecolor($width,$height);
$transparent = imagecolorallocate($output, 0, 0, 0);

//imagealphablending($output, true);
//imagesavealpha($output, true);

imagecopy($output, $input, 10, 10, 0, 0, $width, $height);
imagepng($output,'output.png');
imagedestroy($output);

imagecolortransparent($output, $transparent);
$transparent = imagecolorallocate($output, 0, 0, 0)

?>

输出图像 Output Image

输入图片 Input Image

谢谢!

1 个答案:

答案 0 :(得分:0)

因此有效

<?php
$path = 'images/test1.png';

$input = imagecreatefrompng($path);
$width = imagesx($input);
$height = imagesy($input);

$output = imagecreatetruecolor($width,$height);
$transparent = imagecolorallocate($output, 255, 255, 255);
imagecopy($output, $input, 10, 10, 0, 0, $width, $height);
imagecolortransparent($output, $transparent);

imagepng($output,'images/output.png');
imagedestroy($output);
?>