开发者

PHP Transparent Image Layering Problems

开发者 https://www.devze.com 2022-12-15 22:35 出处:网络
I just can\'t tell why this: <?php $image = imagecreatefromjpeg($_GET[\'u\']); imagealphablending($image, true);

I just can't tell why this:

<?php

     $image = imagecreatefromjpeg($_GET['u']);
     imagealphablending($image, true);
     imagesavealpha($image,true);
     $overlay = imagecreatefrompng("overlay.png");
     imagealphablending($overlay, true);
     imagesavealpha($overlay,true);
     $finalImage = imagecreate(85,85);
     imagealphablending($finalImage, true);
     imagesavealpha($finalImage,true);

     $trans = imagecolorallocate($finalImage,2开发者_JS百科55,0,0);
     imagecolortransparent($finalImage,$trans);
     imagefill($finalImage, 0, 0, $trans);

     imagecopy($finalImage, $image, 5, 5, 0, 0, 75, 75);
     imagecopy($finalImage, $overlay, 0, 0, 0, 0, 85, 85);
     imageDestroy($image);
     imageDestroy($overlay);


     // Content type
     header('Content-type: image/png');
     imagepng($finalImage);
     imagedestroy($finalImage);

?>

Produces this:

alt text http://alanjack.co.uk/travel/0rotatedImage.php%20(1).png

When doing imagecopy one or the other produces healthy results:

         imagecopy($finalImage, $image, 5, 5, 0, 0, 75, 75);
     //imagecopy($finalImage, $overlay, 0, 0, 0, 0, 85, 85);
     //ImageDestroy($image);
     //ImageDestroy($overlay);

giving:

alt text http://alanjack.co.uk/travel/1rotatedImage.php%20(1).png

and

         //imagecopy($finalImage, $image, 5, 5, 0, 0, 75, 75);
     imagecopy($finalImage, $overlay, 0, 0, 0, 0, 85, 85);
     //ImageDestroy($image);
     //ImageDestroy($overlay);

giving:

alt text http://alanjack.co.uk/travel/2rotatedImage.php%20(1).png

Could it be some kind of palette inconsistency or something - something to do with one being a PNG and another a JPEG?

Grrrrrrrr ... Alan angry ... ALAN WANT SMASH!!!


Try this code instead:

<?php

$image = imagecreatefromjpeg($_GET['u']);
imagesavealpha($image, true);
imagealphablending($image, true);

$overlay = imagecreatefrompng("overlay.png");
imagesavealpha($overlay, true);
imagealphablending($overlay, true);

$finalImage = imagecreatetruecolor(85,85);
imagefill($finalImage, 0, 0, IMG_COLOR_TRANSPARENT);
imagesavealpha($finalImage, true);
imagealphablending($finalImage, true);

/*
$trans = imagecolorallocatealpha($finalImage, 255, 0, 0, 127);
imagecolortransparent($finalImage, $trans);
imagefill($finalImage, 0, 0, $trans);
*/

imagecopy($finalImage, $image, 5, 5, 0, 0, 75, 75);
imagecopy($finalImage, $overlay, 0, 0, 0, 0, 85, 85);
//imageDestroy($image);
//imageDestroy($overlay);

// Content type
header('Content-type: image/png');
imagepng($finalImage);
//imagedestroy($finalImage);

?>

Does it solve your problem?


The grey rectangle went away when I changed imagecreate() to imagecreatetruecolor(), so I think it was a palette issue after all!

Thanks anyway guys.

0

精彩评论

暂无评论...
验证码 换一张
取 消