Home > Backend Development > PHP Tutorial > php imagecopy function adds image watermark

php imagecopy function adds image watermark

WBOY
Release: 2016-07-25 08:51:56
Original
1290 people have browsed it
  1. //Add image watermark (random position) to the background image, the background image format is jpeg, and the watermark image format is gif

  2. function watermark($filename,$water){

  3. //Get the width and height of the background image

  4. list($b_w,$b_h) = getimagesize($filename);

  5. //Get the watermark image The width and height of

  6. list($w_w,$w_h) = getimagesize($water);

  7. //Random starting position of the watermark image in the background image

  8. $posX = rand (0, ($b_w-$w_w));
  9. $posY = rand(0, ($b_h-$w_h));

  10. //Resources for creating background images

  11. $back = imagecreatefromjpeg($filename);

  12. //Resources for creating watermark images

  13. $water = imagecreatefromgif($water);

  14. //Use the imagecopy() function Copy the watermark image to the location specified by the background image

  15. imagecopy($back, $water, $posX, $posY, 0, 0, $w_w, $w_h);

  16. //Save Background image with watermark image

  17. imagejpeg($back,$filename);
  18. imagedestroy($back);
  19. imagedestroy($water);
  20. }

  21. //Output watermark image

  22. watermark ("brophp.jpg", "logo.gif");
  23. ?>

Copy code


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template