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

fris on 09/11/08


Tagged

image jpg file imagemagick watermark


Versions (?)


Who likes this?

4 people have marked this snippet as a favorite

SpinZ
luman
mrjthethird
vali29


image watermark


Published in: PHP 


  1. <?
  2.  
  3. function image_watermark($img, $wmg)
  4. {
  5. $ix = imagesx($img);
  6. $iy = imagesy($img);
  7. $wx = imagesx($wmg);
  8. $wy = imagesy($wmg);
  9. $fmg = imagecreatetruecolor($ix, $iy);
  10. imagealphablending($fmg, true);
  11. imagecopy($fmg, $img, 0, 0, 0, 0, $ix, $iy);
  12. for($sx = 0; $sx < $ix; $sx += $wx)
  13. {
  14. for($sy = 0; $sy < $iy; $sy += $wy)
  15. {
  16. imagecopy($fmg, $wmg, $sx, $sy, 0, 0, min($ix - $sx, $wx), min($iy - $sy, $wy));
  17. }
  18. }
  19. return $fmg;
  20. }
  21.  
  22.  
  23. $img = imagecreatefromjpeg('image.jpg');
  24. $wmg = imagecreatefrompng('watermark.png');
  25. $fmg = image_watermark($img, $wmg);
  26. imagejpeg($fmg);
  27.  
  28. ?>

Report this snippet 

You need to login to post a comment.