用PHP制作PNG图像


Make PNG Image with PHP

我正在寻找我们是否可以用php制作PNG图像。

$image = imagecreatetruecolor(100,100);
$black = imagecolorallocate($image,0,0,0);
imagefill($image,0,0,$black);

这将创建 100 X 100 黑色图像。但是,我想创建没有背景的 100 X 100 图像,即 100 X 100 透明图像。

提前致谢

您可以选择

一种颜色成为透明颜色,如下所示:

$im = imagecreatetruecolor(100, 100);
$transparent = imagecolorallocate($im, 0, 0, 0);
imagecolortransparent($im, $transparent);
imagefill($im, 0, 0, $transparent);

取自手动示例:http://php.net/manual/en/function.imagecolortransparent.php

这是你需要的函数:

imagecolorallocatealpha ( resource $image , int $red , int $green , int $blue , int $alpha )

http://www.php.net/manual/en/function.imagecolorallocatealpha.php

$image = imagecreatetruecolor(100,100);
$transparent = imagecolorallocatealpha ($image,0,0,0,0);
imagefill($image,0,0,$transparent);
$image = imagecreatetruecolor(100,100);
imagesavealpha($image, true);
$transparent = 0xFF000000; //0xAARRGGBB
imagefill($image, 0, 0, $transparent);