note 36134 added to function.imagecopy
| From: | pmidden at gmx dot net | Date: | Sat, 27 Sep 2003 13:47:16 +0000 |
| Subject: | note 36134 added to function.imagecopy | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-57193@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_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);
?>
----
Manual Page -- http://www.php.net/manual/en/function.imagecopy.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+36134
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+36134&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+36134&report=yes