Posted By

hasantayyar on 07/28/09


Tagged

php image watermark


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

vali29
umang_nine
huynguye
joethermal


image watermark with php


 / Published in: PHP
 

  1. <?php
  2.  
  3. $main_img = "image.jpg"; // main big photo / picture
  4. $watermark_img = "watermark.gif"; // use GIF or PNG, JPEG has no tranparency support
  5. $padding = 3; // distance to border in pixels for watermark image
  6. $opacity = 100; // image opacity for transparent watermark
  7.  
  8. $watermark = imagecreatefromgif($watermark_img); // create watermark
  9. $image = imagecreatefromjpeg($main_img); // create main graphic
  10.  
  11. if(!$image || !$watermark) die("Error: main image or watermark could not be loaded!");
  12.  
  13.  
  14. $watermark_size = getimagesize($watermark_img);
  15. $watermark_width = $watermark_size[0];
  16. $watermark_height = $watermark_size[1];
  17.  
  18. $image_size = getimagesize($main_img);
  19. $dest_x = $image_size[0] - $watermark_width - $padding;
  20. $dest_y = $image_size[1] - $watermark_height - $padding;
  21.  
  22.  
  23. // copy watermark on main image
  24. imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, $opacity);
  25.  
  26.  
  27. // print image to screen
  28. header("content-type: image/jpeg");
  29. imagejpeg($image);
  30. imagedestroy($image);
  31. imagedestroy($watermark);

Report this snippet  

You need to login to post a comment.