Start New Discussion within our Web Development Community

Simply enough:

Call the function, get the returned filename.

Function Variables:

$file : The input file (source/background)
$destination : Where you want the new watermarked image to go
$overlay : The overlay image (foreground), this is default set (if not passed in) to "images/watermark.png"
$X : X-Position of overlay (default is 10)
$Y : Y-Position of overlay (default is 10)

The return is the destination file (this allows for dynamic watermarks)

Example Usage:

<img src='<?php echo watermark_image("sample.png", "temp/".time().".png"); ?>'>
Nice. Bookmarked this for future reference.
function watermark_image($file, $destination, $overlay = "images/watermark.png", $X = 10, $Y = 10){
	$watermark =		imagecreatefrompng($overlay);
	$source = 		getimagesize($file);
	$source_mime = 		$source['mime'];
	$source_x = 		$source['width'];
	$source_y = 		$source['height'];
	if($source_mime == "image/png"){
		$image = imagecreatefrompng($file);
	}else if($source_mime == "image/jpeg"){
		$image = imagecreatefromjpeg($file);
	}else if($source_mime == "image/gif"){
		$image = imagecreatefromgif($file);
	imagecopy($image, $watermark, $X, $Y, 0, 0, imagesx($watermark), imagesy($watermark));
	imagepng($image, $destination);
	return $destination;