Superposing images

A

Anonymous

Guest
Create image 1.
Create image 2.
Create image 3 with photoshop (or whatever you use to edit images) superposing image1 and image2 and changing the parameters to reach the effect.
 
Fruge said:
Hi,

In fact, I want to do it with PHP ! I need this superposition of two images to be done on-line by users !...

PHP allows to copy images (imagecopy),... but I never found anything about superposing images !

Bye, Fruge

Try read this http://www.php.net/manual/en/function.imagecopyresampled.php
 
I'm sorry, I can't help you...
check this link and have a look, all image functions are there. Maybe you'll find something I couldn't see.

http://www.zend.com/manual/ref.image.php
 
Fruge said:
Yep', "imagecopyresampled()" copies, but it doesn't allow superposing... :'-(

So I think "ImageSuperpose()" is a PHP function to be created :wink:

Thanks,

Fruge !
Interestin where you get this function "ImageSuperpose()"?
PHP not have this function. Maby you're get this function from other language or other library not in GD? See "imagemagick" maby in this library your can get this function.
 
Fruge said:
I meant that it would be a good idea that PHP-developpers create such a function :wink: ! (Of course, it doesn't exist nowadays )
You some not understand, library thas usin in PHP called GD or imagemagic it's not PHP production....
Other peaple create library for PHP.
 
Here is the code necessary to superimpose one image (image02.png) over the top of a second (image01.png).

<?
$img1 = ImageCreateFromPNG('image01.png');
$img2 = ImageCreateFromPNG('image02.png');

ImageCopyMerge($img1, // Destination image
$img2, // Image added to destination
100, // X Coord in img1 for placing img2
150, // Y Coord in img1 for placing img2
0, // X Coord for img2 bounding box start
0, // Y Coord for img2 bounding box start
ImageSx($img2), // X Coord for img2 bounding box end
ImageSy($img2), // Y Coord for img2 bounding box end
100); // Opacity percentage (100 is opaque)

header('Content-Type: image/jpeg');
ImageJPEG($img1,'',90);
destroyImage($img1);
destroyImage($img2);
?>

Quick rundown of the code here. You take the entire secondary image (img2) or a portion of it, depending on the bounding box you create by the last two coordinate pairs in the function call. That portion of the secondary image then gets superimposed onto the first image with its upper-left corner located at the position specified by the function's first coordinate pair. You can then adjust the opacity of the second image to let the initial image show through.

This code works fairly well and with good results, however, I have not found a way to copy the secondary image over the initial image while retaining the transparency of the secondary image. i.e. I have not been able to mask off any of the secondary image when copying. If anyone has any suggestions on this I'd appreciate it.
 
Back
Top