Watermark Images

turt2live

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"); ?>'>
madCoder commented: Nice. Bookmarked this for future reference. +5
458 Views
About the Author

100% Geek not from concentrate.

I tend to do a lot of website making, but I also do heavy development of essentially useless things in Java, C++, and Python.

For example, I made a web-based inventory manager, that doesn't even look pretty.

<?php
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;
}
?>
turt2live 5 Junior Poster in Training

If you would like a sample: Click here

webatz 0 Newbie Poster

zz thank very much
i need it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.