php gd using .gif palette on png image

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
patawic
Forum Newbie
Posts: 1
Joined: Wed Nov 04, 2009 2:48 am

php gd using .gif palette on png image

Post by patawic »

http://wutwilluchoose.info/xbox/copy2.php
Their both in png format.
but for some reason the watermarked image is using a gif palette.
Heres the code that im curently using

Code: Select all

<?php  
header('content-type: image/png');  
$watermark = imagecreatefrompng("http://avatar.xboxlive.com/avatar/I%20patawic%20I/avatar-body.png");  
imagesavealpha($watermark, false);
imagealphablending($watermark, false); 
$watermark_width = imagesx($watermark);  
$watermark_height = imagesy($watermark);  
$image = imagecreatetruecolor($watermark_width, $watermark_height);  
$image = imagecreatefrompng("base.png");  
$size = getimagesize("base.png");  
$dest_x = $size[0] - $watermark_width - 0;  
$dest_y = $size[1] - $watermark_height - 0;  
imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, -120, $watermark_width, $watermark_height, 100);  
imagepng($image);  
imagedestroy($image);  
imagedestroy($watermark);  
?>
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: php gd using .gif palette on png image

Post by McInfo »

Try this.

Code: Select all

<?php
$image = imagecreatetruecolor(150, 300);
$colorBackground = imagecolorallocatealpha($image, 127, 127, 127, 0);
imagefill($image, 0, 0, $colorBackground);
 
$imageBase = imagecreatefrompng('base.png');
imagecopyresampled($image, $imageBase, 0, 0, 0, 0, 150, 135, 150, 135);
 
$imageAvatar = imagecreatefrompng('avatar-body.png');
imagecopyresampled($image, $imageAvatar, 0, 0, 0, 0, 150, 300, 150, 300);
 
if (!headers_sent()) {
    header('Content-Type: image/png');
    imagepng($image);
}
imagedestroy($image);
imagedestroy($imageBase);
imagedestroy($imageAvatar);
Edit: This post was recovered from search engine cache.
Post Reply