how to combine two 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
macewan
Forum Commoner
Posts: 97
Joined: Mon Jul 07, 2003 8:27 pm

how to combine two images.

Post by macewan »

Please excuse me if this post is done incorrectly. This is the php code I will be using to combine two images. Thought maybe someone else would like a copy. See this directory for an example use. The code listed below is referred to as test_02.php & test_02.txt in my testing directory.

Enjoy.

Code: Select all

<?php
$im = "copyright.png";
$out = "jpg"; 
$backgroundfile = "back.jpg";
$image_id = imageCreateFromPNG($im);
$im_X = ImageSX($image_id);
$im_Y = ImageSY($image_id);
$backgroundimage = imageCreateFromJPEG($backgroundfile);
imagecopy($backgroundimage, $image_id, 0, 0, 0, 0, $im_X, $im_Y);
Header( "Content-type: image/jpeg");
  ImageJPEG($backgroundimage);
ImageDestroy($backgroundimage);
ImageDestroy($image_id);
?>
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

thanx! i actually was thinking of overwrighting a tag on a picture when storing it for the site i'm working on, but with this i can leave it as is and have a page place a tag on top on the fly.

probably less efficient but definitely something that will work.
:)
macewan
Forum Commoner
Posts: 97
Joined: Mon Jul 07, 2003 8:27 pm

Post by macewan »

=)
Post Reply