【问题标题】:php png merging issue with imagesphp png合并图像的问题
【发布时间】:2019-08-01 22:33:47
【问题描述】:

我有两张图片要合并,它们的大小都是 150x150 像素。

我想将它们合并成一个 225 宽 x 150 高的新图像。所以图片 2 覆盖了图片 1 的一半。

我做了一些代码,但透明度只适用于 150x150 的新图像,其余的只是黑色背景。

两张图片都有透明背景。

background.png 只是一个大小为 225x150 像素的 png 文件,具有透明背景。

我做错了什么?

$width = "225";
$height = "150";

$dest_image = imagecreatefrompng('background.png');

imagesavealpha($dest_image, true);            
$trans_background = imagecolorallocatealpha($dest_image, 0, 0, 0, 127);
imagefill($dest_image, 0, 0, $trans_background);

$a = imagecreatefrompng('9.png');
$b = imagecreatefrompng('90.png');

imagecopy($dest_image, $a, 0, 0, 0, 0, $width, $height);
imagecopy($dest_image, $b, 75, 0, 0, 0, $width, $height);

header('Content-Type: image/png');
imagepng($dest_image);

imagedestroy($a);
imagedestroy($b);
imagedestroy($dest_image);

【问题讨论】:

    标签: php image png


    【解决方案1】:
    imagecopy($dest_image, $a, 75, 0, 0, 0, $width, $height);
    imagecopy($dest_image, $b, 0, 0, 0, 0, 150, $height);
    

    只是位置问题 - 已修复:)

    【讨论】:

      猜你喜欢
      • 2019-03-12
      • 1970-01-01
      • 2011-06-02
      • 1970-01-01
      • 2012-03-11
      • 2023-04-04
      • 1970-01-01
      • 2011-10-18
      • 2012-03-26
      相关资源
      最近更新 更多