Please find the attached files showing you a demo on how to water mark images in php.
demo.php
- Code: Select all
<html>
<head>
<title>Water Marking Demo</title>
</head>
<body>
<h2>Original Image</h2>
<img src="shop.jpg" width="306" height="160" alt="" title="" />
<br />
<br />
<h2>Image with Water-mark</h2>
<img src="watermark.php?img=shop.jpg" width="306" height="160" alt="" title="" />
</body>
</html>
watermark.php
- Code: Select all
<?
$sSrcImagePath = $_REQUEST['img'];
$sImgWatermark = imagecreatefrompng('watermark.png');
$iWatermarkWidth = imagesx($sImgWatermark);
$iWatermarkHeight = imagesy($sImgWatermark);
$sImgSource = imagecreatefromjpeg($sSrcImagePath);
list($iSourceWidth, $iSourceHeight) = getimagesize($sSrcImagePath);
$iWatermarkX = 0;
$iWatermarkY = ($iSourceHeight - $iWatermarkHeight);
imagecopy($sImgSource, $sImgWatermark, $iWatermarkX, $iWatermarkY, 0, 0, $iWatermarkWidth, $iWatermarkHeight);
header('content-type: image/jpeg');
imagejpeg($sImgSource, NULL, 100);
imagedestroy($sImgSource);
imagedestroy($sImgWatermark);
?>