We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Posted By

luman on 09/21/08


Tagged

watermark


Versions (?)


Who likes this?

5 people have marked this snippet as a favorite

elgermano
wizard04
Scooter
vali29
ginoplusio


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.