Join the forums now, and start posting to receive access to our Scripts Vault!
<?phpsession_start();//body is never empty$im = imagecreatefrompng("images/chars/body" . str_replace(' ', '',$_SESSION['body'] . ".png"));//set pixel color for transparent$green = imagecolorallocate($im, 51, 153, 0);// Make the background transparentimagecolortransparent($im, $green);//bottomif(!empty($_SESSION['bot'])){ $newImage = imagecreatefrompng("images/chars/bot" . str_replace(' ', '',$_SESSION['bot']) . ".png"); //set pixel color for transparent $green = imagecolorallocate($newImage, 51, 153, 0); // Make the background transparent imagecolortransparent($newImage, $green); imagecopymerge($newImage, $im, 0, 0, 0, 0, 48, 64, 0);}//topif(!empty($_SESSION['top'])){ if(!empty($_SESSION['bot'])) { $newImage = imagecreatefrompng("images/chars/top" . str_replace(' ', '',$_SESSION['top']) . ".png"); //set pixel color for transparent $green = imagecolorallocate($newImage, 51, 153, 0); // Make the background transparent imagecolortransparent($newImage, $green); // Copy and merge imagecopymerge($newImage, $im, 0, 0, 0, 0, 48, 64, 0); // Content type header('Content-type: image/png'); imagepng($newImage); } else { $newImager = imagecreatefrompng("images/chars/bot" . str_replace(' ', '',$_SESSION['bot']) . ".png"); //set pixel color for transparent $green = imagecolorallocate($newImager, 51, 153, 0); // Make the background transparent imagecolortransparent($newImager, $green); imagecopymerge($newImager, $im, 0, 0, 0, 0, 48, 64, 0); // Content type header('Content-type: image/png'); imagepng($newImager); }}?>
<?phpsession_start();$rgb = "32, 156, 0";//body is never empty$im = imagecreatefrompng("images/chars/body" . str_replace(' ', '',$_SESSION['body'] . ".png"));//set pixel color for transparent$green = imagecolorallocate($im, 32, 156, 0);// Make the background transparentimagecolortransparent($im, $green);// Turn off alpha blending and set alpha flagimagealphablending($im, false);imagesavealpha($im, true);//bottomif(!empty($_SESSION['bot'])){ $newImage = imagecreatefrompng("images/chars/bot" . str_replace(' ', '',$_SESSION['bot']) . ".png"); //set pixel color for transparent $green = imagecolorallocate($newImage, 32, 156, 0); // Make the background transparent imagecolortransparent($newImage, $green); // Turn off alpha blending and set alpha flag imagealphablending($newImage, false); imagesavealpha($newImage, true); imagecopymerge($im, $newImage, 0, 0, 0, 0, 48, 64, 75); //set pixel color for transparent $green = imagecolorallocate($im, 32, 156, 0); // Make the background transparent imagecolortransparent($im, $green);}//topif(!empty($_SESSION['top'])){ $newImager = imagecreatefrompng("images/chars/top" . str_replace(' ', '',$_SESSION['top']) . ".png"); //set pixel color for transparent $green = imagecolorallocate($newImager, 32, 156, 75); // Make the background transparent imagecolortransparent($newImager, $green); // Turn off alpha blending and set alpha flag imagealphablending($newImager, false); imagesavealpha($newImager, true); imagecopymerge($im, $newImager, 0, 0, 0, 0, 48, 64, 75);}// Content typeheader('Content-type: image/png');imagepng($im);?>
<?php $imgOutput = imagecreatetruecolor(48, 64); imagefill($imgOutput, 0, 0, 0); $imgBody = imagecreatefrompng("body.png"); imagecolortransparent($imgBody, imagecolorat($imgBody, 0, 0)); $imgBeard = imagecreatefrompng("beard.png"); imagecolortransparent($imgBeard, imagecolorat($imgBeard, 0, 0)); $imgArmour = imagecreatefrompng("armour.png"); imagecolortransparent($imgArmour, imagecolorat($imgArmour, 0, 0)); imagecopymerge($imgOutput, $imgBody, 0, 0, 0, 0, 48, 64, 100); imagecopymerge($imgOutput, $imgBeard, 0, 0, 0, 0, 48, 64, 100); imagecopymerge($imgOutput, $imgArmour, 0, 0, 0, 0, 48, 64, 100); imagepng($imgOutput, './imagecolortransparent.png'); imagedestroy($imgOutput); exit;?>
I know it's not a solution to the GD problem, but we've moved to Image Magick for all our processing needs. SO. Much. Better. If you CAN do it, I'd highly recommend it.
Code: [Select]<?php $imgOutput = imagecreatetruecolor(48, 64); imagefill($imgOutput, 0, 0, 0); $imgBody = imagecreatefrompng("body.png"); imagecolortransparent($imgBody, imagecolorat($imgBody, 0, 0)); $imgBeard = imagecreatefrompng("beard.png"); imagecolortransparent($imgBeard, imagecolorat($imgBeard, 0, 0)); $imgArmour = imagecreatefrompng("armour.png"); imagecolortransparent($imgArmour, imagecolorat($imgArmour, 0, 0)); imagecopymerge($imgOutput, $imgBody, 0, 0, 0, 0, 48, 64, 100); imagecopymerge($imgOutput, $imgBeard, 0, 0, 0, 0, 48, 64, 100); imagecopymerge($imgOutput, $imgArmour, 0, 0, 0, 0, 48, 64, 100); imagepng($imgOutput, './imagecolortransparent.png'); imagedestroy($imgOutput); exit;?>This will output the result to a black background, if you would like that changed to a different color or image change the first two lines that define the output. I did not define a var for the transparency color as they may be slightly different across the images.