|
OK, this code is somewhat improved over what I sent you, but mostly in terms of clarity.
<?php
header ("Content-type: image/jpeg");
//assign picture to show
$filename = 'sample.jpg';
$img_des = ImageCreateFromJpeg ($filename);
//assign stamp picture
$filename2 = 'a.jpg';
$img_src = ImageCreateFromJpeg ($filename2);
//calc the size of the stamp image
$size = getimagesize($filename2);
//set opacity value of the stamp
$opacity = 15;
//set the margins size for the stamp image. Our stamp image is 50 by 50 pixels
// make sure this value is >= stamp width
// or else the stamp's right edge will be chopped
//Here we will have 60-50=10px margin to the right of the stamp
$rightmargin = 60;
// make sure the value is >= stamp height
// or else the stamp's bottom edge will be chopped
//Here we will have 60-50=10px margin rom the bottom of the stamp
$bottommargin = 60;
//merge the two images
ImageCopyMerge($img_des, $img_src, imagesx($img_des)-$rightmargin, imagesy($img_des)-$bottommargin, 0, 0, $size[0], $size[1], $opacity);
//display the image in browser
ImageJPEG ($img_des);
//destroy memory allocated to image handles
ImageDestroy ($img_src);
ImageDestroy ($img_des);
?>
This code is not a marvel, but as I said, I'm still trying to get the feel of that PHP thingie.
Also, bear in mind that this code will NOT modify any of the pictures used in the process. The stamp is dynamically superimposed onto the destination image and the result streamed to the browser without savin the modifications on the server.
Important: the PHP on the server must be compiled with GD library. Otherwise will error out with "function not found" message.
Sample pictures will look like this:
<edit: clarified comments on margins>
|