Watermark


 / Published in: PHP
 

  1. function watermark($imagesource){
  2. $filetype = substr($imagesource,strlen($imagesource)-4,4);
  3. $filetype = strtolower($filetype);
  4. if($filetype == ".gif") $image = @imagecreatefromgif($imagesource);
  5. if($filetype == ".jpg") $image = @imagecreatefromjpeg($imagesource);
  6. if($filetype == ".png") $image = @imagecreatefrompng($imagesource);
  7. if (!$image) die();
  8. $watermark = @imagecreatefrompng('../images/watermark.png');
  9. $imagewidth = imageSX($image);
  10. $imageheight = imageSY($image);
  11. $watermarkwidth = imageSX($watermark);
  12. $watermarkheight = imageSY($watermark);
  13. $startwidth = $imagewidth - $watermarkwidth - 5;
  14. $startheight = $imageheight - $watermarkheight - 5;
  15. imagecopy($image, $watermark, $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight);
  16. imagejpeg($image,$imagesource);
  17. imagedestroy($image);
  18. imagedestroy($watermark);
  19. }

Report this snippet  

You need to login to post a comment.