watermark an image example

watermark an image example

Using this on our iwantfreebies site

<?php

header('content-type: image/jpeg'); //content type is a jpeg

$watermark = imagecreatefrompng('watermark.jpg'); //this is the watermark we are using
//gets the dimensions of the watermark image
$width = imagesx($watermark);
$height = imagesy($watermark);
$image = imagecreatetruecolor($width, $height);
//image to be watermarked
$image = imagecreatefromjpeg("sampleimage.jpg");
//get the size of the image
$size = getimagesize("sampleimage.jpg");
$dest_x = $size[0] - $width - 5;
$dest_y = $size[1] - $height - 5;
//copy watermark on to image
imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $width, $height, 100);
imagejpeg($image);
//important to clean up
imagedestroy($image);
imagedestroy($watermark);

?>