使用php旋转png图像后如何获得透明背景?

Chr*_*ris 6 php rotation

所以我有png图像,我旋转它,但我得到一个黑色的背景..或如果我做白色的颜色代码我得到白色..我试过这样做..

$trans = imagecolorallocatealpha(image, 0, 0, 0, 127);
imagerotate($image, $degree, $trans)
Run Code Online (Sandbox Code Playgroud)

我也试过..

$trans = imagecolorallocatealpha($image, 255, 255, 255, 127);
Run Code Online (Sandbox Code Playgroud)

有人可以帮我吗?

这是我的代码..如果我将allocatealpha更改为0,0,255,0然后它变为蓝色.但是0,0,0,127仍为黑色.

function rotate($degrees) {
$image = $this->image;
imagealphablending($image, false);
$color = imagecolorallocatealpha($image, 0, 0, 0, 127);
imagefill($this->image, 0, 0, $color);
$rotate = imagerotate($image, $degrees, $color);
imagesavealpha($image, TRUE);
$this->image = $rotate;

Mic*_*son 10

$destimg = imagecreatefromjpeg("image.png");
$transColor = imagecolorallocatealpha($destimg, 255, 255, 255, 127);
$rotatedImage = imagerotate($destimg, 200, $transColor);
imagesavealpha($rotatedImage, true);
imagepng($rotatedImage,"rotated.png");
Run Code Online (Sandbox Code Playgroud)

  • "imagecreatefromjpeg("image.png")"应该是"imagecreatefrompng("image.png")" (2认同)

Tru*_*ufa 0

你试过这个吗?

图像颜色透明

希望我理解你的问题!