note 36134 modified in function.imagecopy by vincent
| From: | vincent@php.net | Date: | Wed, 22 Oct 2003 17:23:52 +0000 |
| Subject: | note 36134 modified in function.imagecopy by vincent | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-59141@lists.php.net to get a copy of this message | ||
I've found a convenient way to "blit" one image into another. Using the following
Code you can copy one image into another, leaving out the pixels with the specified transparent
color. I'm using PNG but by replacing all PNG functions by JPEG or GIF functions you are able
to use those formats as well:
<?php
$background = imagecreatefrompng("background.png");
$insert = imagecreatefrompng("insert.png");
// Either a color at a specific point on the image
// imagecolortransparent($insert,imagecolorat($insert,0,0));
// or a specific color (the color I used is magenta, #ff00ff)
imagecolortransparent($insert,imagecolorexact($insert,255,0,255));
$insert_x = imagesx($insert);
$insert_y = imagesy($insert);
// As said above, you can't use imagecopy (bug?)
imagecopymerge($background,$insert,0,0,0,0,$insert_x,$insert_y,100);
// imagejpeg or imagepng doesn't matter here
imagejpeg($background,"",100);
?>
--was--
I've found a convenient way to "blit" one image into another. Using the following
Code you can copy one image into another, leaving out the pixels with the specified transparent
color. I'm using PNG but by replacing all PNG functions by JPEG or GIF functions you are able
to use those formats as well:
<?php
$background = imagecreatefrompng("background.png");
$insert = imagecreatefrompng("insert.png");
// Either a color at a specific point on the image
// imagecolortransparent($insert,imagecolorat($insert,0,0));
// or a specific color (the color I used is magenta, #ff00ff)
imagecolortransparent($insert,imagecolorexact($insert,255,0,255));
$insert_x = imagesx($insert_x);
$insert_y = imagesy($insert_y);
// As said above, you can't use imagecopy (bug?)
imagecopymerge($background,$insert,0,0,0,0,$insert_x,$insert_y,100);
// imagejpeg or imagepng doesn't matter here
imagejpeg($background,"",100);
?>
http://www.php.net/manual/en/function.imagecopy.php