使用GD库叠加图像使其具有灰度级.为什么?


superimposing images using GD Library makes them grayscale. Why?

我有两个PNG图像,我想创建一个新的PNG图像。第一图像将被超级施加在其上。代码工作得很好,正在生成预期的图像,但所有的颜色都丢失了,输出是灰度图像。

这是我的代码

Phone.png文件为"http://i44.tinypic.com/2vwilb8.png"背景.png是"http://i43.tinypic.com/2194eu9.png"

    $backgroundImage = 'background.png';
    $userImage = "http://graph.facebook.com/4/picture?type=large";
    $resultImage ='phone.png';

    $background = imagecreatefrompng($backgroundImage);
    $userResultImage = imagecreatefromjpeg($userImage);
    $result = imagecreatefrompng($resultImage);

    list($backgroundWidth, $backgroundHeight) = getimagesize($backgroundImage);
    list($userImageWidth, $userImageHeight) =  getimagesize($userImage);
    list($resultRightItemWidth, $resultRightItemHeight) = getimagesize($resultImage);
    $newWidth = 800;
    $newHeight = 800;
    $new = imagecreate($newWidth, $newHeight);
    imagealphablending($new, false);
    imagesavealpha($new, true);
    imagecopy($new, $background, 0, 0, 0, 0, $backgroundWidth, $backgroundHeight);
    imagecopy($new, $userResultImage, 40, 300, 0, 0, $userImageWidth, $userImageHeight);
    header('Content-type: image/png');
    imagepng($new,'asdas.png');
    imagecopy($new, $result, 490, 170, 0, 0, $resultRightItemWidth, $resultRightItemHeight);
    header('Content-type: image/png');
    imagepng($new, $userID.'.png');

您应该使用imagecreatetruecolor()而不是imagecreate()。。。