Combining PNG Images?

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
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Combining PNG Images?

Post 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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Combining PNG Images?

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Re: Combining PNG Images?

Post by psychotomus »

I done looked through the GD image functions. didnt find nething unless I overlooked it. I look again.
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Re: Combining PNG Images?

Post by psychotomus »

cool cool thanks thanks
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Re: Combining PNG Images?

Post 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);
 
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Re: Combining PNG Images?

Post by psychotomus »

what you mean?
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Re: Combining PNG Images?

Post by psychotomus »

ahh a typo. let me see if that works.
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Re: Combining PNG Images?

Post 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);
Post Reply