我正在使用 PHP GB 库来操作图像。我注意到 GB 库没有附带的一件事是能够垂直或水平翻转图像。所以我开始为它构建自己的功能。这就是我得到的:
function flipImage($image) {
$width = imagesx($image);
$height = imagesy($image);
$out = imagecreatetruecolor($width, $height);
for($i = 0; $i < $width; $i++) {
// Copy the image strip going left to right
imagecopy($out, $image, $width - $i, 0, $i, 0, 1, $height);
}
//$out should now hold our flipped image
return $out;
}
它按我的预期工作,但由于某种原因,返回的图像 ( $out
) 具有黑色背景而不是透明背景。
有没有办法让返回的图像像源图像一样具有透明背景?