1,105,578 Community Members

Watermark Images

Member Avatar
(turt2live)
Reputation Points: 5 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
1
 

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"); ?>'>
<?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;
}
?>
Member Avatar
turt2live
Junior Poster in Training
90 posts since Jan 2011
Reputation Points: 5 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

If you would like a sample: Click here

Member Avatar
webatz
Newbie Poster
1 post since Mar 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

zz thank very much
i need it

You
Post:
Start New Discussion
View similar articles that have also been tagged: