Page 1 of 1

Combining PNG Images?

Posted: Thu Aug 06, 2009 12:35 pm
by psychotomus
I don't think my png images have transparency, so how would I go about making them transparent then combing them?


Image
Image

Re: Combining PNG Images?

Posted: Thu Aug 06, 2009 2:21 pm
by pickle
I think when you're working with the file, there's a way to set a particular colour as transparent. Check the GD functions.

Re: Combining PNG Images?

Posted: Thu Aug 06, 2009 2:41 pm
by psychotomus
I done looked through the GD image functions. didnt find nething unless I overlooked it. I look again.

Re: Combining PNG Images?

Posted: Fri Aug 07, 2009 4:36 pm
by psychotomus
cool cool thanks thanks

Re: Combining PNG Images?

Posted: Fri Aug 07, 2009 5:41 pm
by psychotomus
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

Code: Select all

 
 
$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);
 

Re: Combining PNG Images?

Posted: Sat Aug 08, 2009 5:06 pm
by psychotomus
what you mean?

Re: Combining PNG Images?

Posted: Tue Aug 11, 2009 3:15 pm
by psychotomus
ahh a typo. let me see if that works.

Re: Combining PNG Images?

Posted: Tue Aug 11, 2009 3:19 pm
by psychotomus
still same result:

Code: Select all

$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, $rgb);
}
 
//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, $rgb);
        
        // Copy and merge
        imagecopymerge($im, $head, 0, 0, 0, 0, imagesx($im), imagesy($im), 75);
    }
    else
    {
        //load head
        $im = imagecreatefrompng("data/paperdoll/" . $_SESSION['Head']);
        $rgb = imagecolorat($im, 1, 1);
        imagecolortransparent($im, $rgb);
    }
}
 
//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, $rgb);
        
        // Copy and merge
        imagecopymerge($im, $hair, 0, 0, 0, 0, imagesx($im), imagesy($im), 75);
    }
    else
    {
        //load head
        $im = imagecreatefrompng("data/paperdoll/" . $_SESSION['Hair']);
        $rgb = imagecolorat($im, 1, 1);
        imagecolortransparent($im, $rgb);
    }
}
 
//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, $rgb);
        
        // 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, $rgb);
    }
}
 
// Output and free from memory
header('Content-Type: image/png');
imagepng($im);