0

How can I apply a watermark to an uploaded picture using PHP?

Example LINK: http://www.kitebeaches.com/kitesurf/uploadPicture/NIRVANA_Club_Village.html

Dominic Rodger
  • 97,747
  • 36
  • 197
  • 212
Fero
  • 12,969
  • 46
  • 116
  • 157

2 Answers2

5

Previously on SO:

Community
  • 1
  • 1
karim79
  • 339,989
  • 67
  • 413
  • 406
1

Try this (adapted from sitepoint):

<?php  

header('content-type: image/jpeg');  
$yourimagefile = 'something.jpg' // the image you're wanting to watermark
$watermark = imagecreatefrompng('watermark.png');  // the watermark
$watermark_width = imagesx($watermark);  
$watermark_height = imagesy($watermark);  
$image = imagecreatetruecolor($watermark_width, $watermark_height);  
$image = imagecreatefromjpeg($yourimagefile);  
$size = getimagesize($yourimagefile);  
$dest_x = $size[0] - $watermark_width - 5;  
$dest_y = $size[1] - $watermark_height - 5;  
imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);  
imagejpeg($image);  
imagedestroy($image);  
imagedestroy($watermark);  
Dominic Rodger
  • 97,747
  • 36
  • 197
  • 212
  • 2
    I'd highly recommend WideImage for this sort of thing: http://wideimage.sourceforge.net/tutorials/watermarkmerge/ – deceze Sep 14 '09 at 11:26