我正在从另外两个图像创建一个PNG图像。
图像A和B具有相同的尺寸,它们都是200x400px。最终的图像是一样的。
我在PHP中使用GD库。
所以我的想法是从我原来的PNG-8创建一个PNG-24,然后使用彩色透明度,最后将第二个图像复制到这个新的PNG-24中。当从PNG-24转到具有颜色透明度的PNG-8时,问题无论如何都会出现在第一步中:
这是为了获得原始的PNG-8和它的尺寸:
$png8 = imagecreatefrompng($imageUrl);
$size = getimagesize($imageUrl);现在我创建一个新的PNG,并用绿色填充它的背景(图像中没有出现):
$png24 = imagecreatetruecolor($size[0], $size[1]);
$transparentIndex = imagecolorallocate($png24, 0x66, 0xff, 0x66);
imagefill($png24, 0, 0, $transparentIndex);这是为了使绿色透明:
imagecolortransparent($png24, $transparentIndex); 然后我将png8复制到PNG-24中:
imagecopy($png24, $png8, 0, 0, 0, 0, $size[0], $size[1]);所以问题来了:原始的PNG-8看起来不错,但它在原始图像中的形状周围有一个绿色的边框。这真的很难解释。似乎在剩余的PNG中留下了绿色背景的一部分。
我能做什么?
提前感谢
诚挚的问候,
费尔南多
发布于 2011-07-05 03:20:21
我之前在png透明度方面遇到了一些问题,并能够通过以下模式解决这些问题:
// allocate original image to copy stuff to
$img = imagecreatetruecolor(200, 100);
// create second image
$bg = imagecreatefrompng('bg.png');
// copy image onto it using imagecopyresampled
imagecopyresampled($img, $bg, 0, 0, 0, 0, 200, 100, 200, 100);
imagedestroy($bg);
// create third image
// do same routine
$fg = imagecreatefrompng('fg.png');
imagecopyresampled($img, $fg, 50, 50, 0, 0, 50, 50, 50, 50);
imagedestroy($fg);
// output image
imagepng($img);
imagedestroy($img);我想我的和你的唯一的区别就是imagecopy()和imagecopyresampled()。虽然那是很久以前的事了,但我似乎记得有过一些问题。你可以在这里看到我使用这个模式的一个图像的例子:http://www.ipnow.org/images/1/bggrad/bg4/yes/TRANSIST.TTF/8B0000/custombrowserimage.jpg (我分配一个空白图像,复制背景图像,复制带有透明度的覆盖图)
https://stackoverflow.com/questions/6575016
复制相似问题