Page 1 of 1
transparency images
Posted: Mon Feb 07, 2011 12:47 pm
by psychotomus
I got 3 images and I want to merge them. None of the images should overlap except for the color I want transparent. I want the body first, bottom 2nd and top go 3rd. what should functions should I use? =)
Re: transparency images
Posted: Mon Feb 07, 2011 2:29 pm
by pickle
I've never done anything like this before, but there are 2 possible methods I can think of.
1) Set that green as a transparent colour, then copy the entirety of one image onto the other. I'm not sure if that will overwrite legitimate pixel colours or not.
2) Create an image object in PHP. For each of those image, iterate through each pixel. If the pixel isn't that magic transparent colour, create a matching pixel at the same co-ordinates in the newly created object. After all images are iterated through, you should have a combination of all three in one image.
Re: transparency images
Posted: Wed Feb 09, 2011 1:52 pm
by psychotomus
pickle wrote:I've never done anything like this before, but there are 2 possible methods I can think of.
1) Set that green as a transparent colour, then copy the entirety of one image onto the other. I'm not sure if that will overwrite legitimate pixel colours or not.
How do I set a pixel as transparent?
Re: transparency images
Posted: Wed Feb 09, 2011 2:04 pm
by pickle
Re: transparency images
Posted: Wed Feb 09, 2011 2:25 pm
by psychotomus
Thanks. How I get the rgb of my green pixel? ;']
Re: transparency images
Posted: Wed Feb 09, 2011 2:29 pm
by pickle
Sounds like you need to do some investigation into the GD functions available in PHP. Or bring the image into an image editor & click on the pixel with an eyedropper.
Re: transparency images
Posted: Wed Feb 09, 2011 3:13 pm
by psychotomus
Ive done little work with GD in the past. Been a year since ive touched GD though.
Anyway, here's what I got:
Code: Select all
<?php
session_start();
//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 transparent
imagecolortransparent($im, $green);
//bottom
if(!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);
imagecopymerge($newImage, $im, 0, 0, 0, 0, 48, 64, 0);
}
//top
if(!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, 32, 156, 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, 32, 156, 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);
}
}
?>
located at:
http://www.phpengines.info/tactical/indexcreate.php It don't work =0
Re: transparency images
Posted: Thu Feb 10, 2011 12:15 pm
by psychotomus
Ive made some progress but not what i am looking for still.
http://phpengines.info/tactical/indexcreate.php
Code: Select all
<?php
session_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 transparent
imagecolortransparent($im, $green);
//bottom
if(!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);
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);
}
//top
if(!empty($_SESSION['top']))
{
$newImager = imagecreatefrompng("images/chars/top" . str_replace(' ', '',$_SESSION['top']) . ".png");
//set pixel color for transparent
$green = imagecolorallocate($newImager, 32, 156, 0);
// Make the background transparent
imagecolortransparent($newImager, $green);
imagecopymerge($im, $newImager, 0, 0, 0, 0, 48, 64, 50);
}
// Content type
header('Content-type: image/png');
imagepng($im);
?>