chxxangie Posted October 26, 2008 Share Posted October 26, 2008 i have two images. let assume is same size. is it possible to "add" two images become one? just like overlap... plz help.. Quote Link to comment Share on other sites More sharing options...
Jeremysr Posted October 26, 2008 Share Posted October 26, 2008 First load your two images: $image1 = imagecreatefrompng('image1.png'); $image2 = imagecreatefrompng('image2.png'); Then create your new image calculating the width and height from the previous two images. If you want the images side-by-side, the width of the new image will be the width of the first image plus the width of the second image. $new_image_width = imagesx($image1) + imagesx($image2); $new_image_height = max(imagesy($image1), imagesy($image2)); // Make height the height of the taller image. $new_image = imagecreatetruecolor($new_image_width, $new_image_height); Finally, copy the two images onto your new image and output the image. imagecopy($new_image, $image1, 0, 0, 0, 0, imagesx($image1), imagesy($image1)); imagecopy($new_image, $image2, imagesx($image1), 0, 0, 0, imagesx($image2), imagesy($image2)); imagepng($new_image); See imagecopy() for more information. Quote Link to comment Share on other sites More sharing options...
chxxangie Posted October 26, 2008 Author Share Posted October 26, 2008 <?php $image1 = imagecreatefromjpeg("images/thumbs/my_image-thumb.jpg"); $image2 = imagecreatefromjpeg("template_new.jpg"); $new_image_width = imagesx($image2); $new_image_height = imagesy($image2); $new_image = imagecreatetruecolor($new_image_width, $new_image_height); imagecopy($new_image, $image1, 0, 0, 0, 0, imagesx($image2), imagesy($image2)); imagecopy($new_image, $image2, 0, 0, 0, 0, imagesx($image2), imagesy($image2)); imagejpeg($new_image,'final2.jpg'); ?> my $image2 can be said is the background. then, i want to make $image1 overlap to $image2 and follow $image2 width and height. so $image1 need to resize to the same size with $image2. i try to modify the code. but the result come out is only $iamge2 without $image1. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.