2010-11-11 63 views
8

我昨天整天试图弄清楚这一点。我通过imagerotate()旋转图像。我得到一个黑色的背景,图像不再覆盖。我已经试过各种我想不出来作出这样的背景透明..为什么我不能在使用php旋转后使png透明背景?

这里是我当前的代码..

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

我真的开始变得勾掉。有人可以给我看一些工作代码吗?请?

难道我的WAMP服务器和Dreamweaver有问题吗?因为我甚至试过这个.. http://www.exorithm.com/algorithm/view/rotate_image_alpha它仍然熄灭无论是黑色或白色背景..

+2

仿佛就在昨天的问题的副本。 http://stackoverflow.com/questions/4148774/how-do-i-get-a-transparent-background-after-rotaing-a-png-image-with-php/4148805 – stevelove 2010-11-11 18:59:52

+0

是的。我知道我真的不应该再次发布,但你不知道我想这个代码有多严重,只是工作已经.. – Chris 2010-11-11 19:07:31

+0

请指定您的PHP版本。 – Rolf 2010-12-06 12:07:27

回答

1

尝试设置imagesavealpha()在您的旋转图像。

当前您正在原始图像上运行imagesavealpha()。 [例如。 imagesavealpha($ image,true); ]

相反,你要运行imagesavealpha()旋转的图像,然后设置$这个 - >图像...尝试:

... 
    $rotate = imagerotate($image, $degrees, $color); 
    imagecolortransparent($rotate, $color); 
    imagesavealpha($rotate, true); // <- using $rotate instead of $image 
    $this->image = $rotate; 

}