Making PNG Images Transparent?

Discussion in 'PHP' started by SimThePhpCoder, Aug 7, 2009.

  1. #1
    Doesn't seem like its making the images transparent before merging them. anybody know what i'm doing wrong?

    http://tacticalrpgengine.com/demo22/charcreate.php

     
     
    $id = mysql_real_escape_string($_GET['id']);
     
    //paperdoll parts
    $result = mysql_query("SELECT dolltype, dollfname FROM paperdolling WHERE id='$id'") or die(mysql_error());
    $paperdoll = mysql_fetch_object($result);
     
    //session var
    $_SESSION[$paperdoll->dolltype] = $paperdoll->dollfname;
     
    //fix body
    if(isset($_SESSION['Body']))
    {
     
        $im = imagecreatefrompng("data/paperdoll/" . $_SESSION['Body']);
        $rgb = imagecolorat($im, 1, 1);
        imagecolortransparent($im, $rbg);
    }
     
    //fix head
    if(isset($_SESSION['Head']))
    {
        //if body is set, merge body and head
        if(isset($_SESSION['Body']))
        {
            //load head
            $head = imagecreatefrompng("data/paperdoll/" . $_SESSION['Head']);
            $rgb = imagecolorat($head, 1, 1);
            imagecolortransparent($head, $rbg);
            
            // Copy and merge
            imagecopymerge($im, $head, 0, 0, 0, 0, imagesx($im), imagesy($im), 25);
        }
        else
        {
            //load head
            $im = imagecreatefrompng("data/paperdoll/" . $_SESSION['Head']);
            $rgb = imagecolorat($im, 1, 1);
            imagecolortransparent($im, $rbg);
        }
    }
     
    //fix hair
    if(isset($_SESSION['Hair']))
    {
        //if body is set, merge body and head
        if(isset($_SESSION['Body']) || isset($_SESSION['Head']) )
        {
            //load hair
            $hair = imagecreatefrompng("data/paperdoll/" . $_SESSION['Hair']);
            $rgb = imagecolorat($hair, 1, 1);
            imagecolortransparent($hair, $rbg);
            
            // Copy and merge
            imagecopymerge($im, $hair, 0, 0, 0, 0, imagesx($im), imagesy($im), 0);
        }
        else
        {
            //load head
            $im = imagecreatefrompng("data/paperdoll/" . $_SESSION['Hair']);
            $rgb = imagecolorat($im, 1, 1);
            imagecolortransparent($im, $rbg);
        }
    }
     
    //fix clothes
    if(isset($_SESSION['Clothes']))
    {
        //if body is set, merge body and head
        if(isset($_SESSION['Body']) || isset($_SESSION['Head']) || isset($_SESSION['Hair']))
        {
            //load clothes
            $clothes= imagecreatefrompng("data/paperdoll/" . $_SESSION['Clothes']);
            $rgb = imagecolorat($clothes, 1, 1);
            imagecolortransparent($clothes, $rbg);
            
            // Copy and merge
            imagecopymerge($im, $clothes, 0, 0, 0, 0, imagesx($im), imagesy($im), 75);
        }
        else
        {
            //load clothes
            $im = imagecreatefrompng("data/paperdoll/" . $_SESSION['Clothes']);
            $rgb = imagecolorat($im, 1, 1);
            imagecolortransparent($im, $rbg);
        }
    }
     
    // Output and free from memory
    header('Content-Type: image/png');
    imagepng($im);
     
    Code (text):
     
    SimThePhpCoder, Aug 7, 2009 IP
  2. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You may have to add this: (not sure)

    imagealphablending($im, false);
    imagesavealpha($im,true);
    PHP:
     
    premiumscripts, Aug 8, 2009 IP