使用PHP GD与另一个png图像合并时,从png图像中删除透明空间

时间:2016-11-08 12:42:20

标签: php image gd

我正在使用php-gd在我的php代码中合并两个png图像。图像正在合并,但问题是图像中有额外的透明空间我想要删除。

这是我的PHP代码。

<?php

$image1Url = "/home/sunpure-refined-sunflower-oil-v-5-ltr-1.png";
$image2Url = "/home/hypercity-every-day-sooji-rawa-v-1-kg-6.png";    

$dest = imagecreatefrompng($image1Url);
$src = imagecreatefrompng($image2Url);

$offset2x = imagesx($src);
$offset3x = imagesx($dest);

$temp = imagecreatetruecolor($offset2x + $offset3x, 140);
$background = imagecolorallocate($temp, 0, 0, 0);
imagecolortransparent($temp, $background);

imagecopymerge($temp, $src, 0, 0, 0, 0, 180, 180, 100); //have to play with these numbers for it to work for you, etc.
imagecopymerge($temp, $dest, $offset2x-50, 0, 0, 0, 180, 180, 100);
header('Content-Type: image/png');
imagepng($temp, "/home/myImage.png");

imagedestroy($dest);
imagedestroy($src);

Here is my merged image Here is my second image where I am trying to overlap some part of the image to first image. However there is extra transparent space which does not look good

在最右边的图像中,我试图去除它们之间的空间,但由于透明空间,它没有发生。

0 个答案:

没有答案