Added an image watermark using the phpimagecopy function.

Source: Internet
Author: User
Tags imagecopy
Added an image watermark using the phpimagecopy function.

  1. // Add an 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. // Obtain the width and height of the background image.

  4. List ($ B _w, $ B _h) = getimagesize ($ filename );

  5. // Obtain the width and height of the watermark image

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

  7. // Place the watermark position in the background image at random start position

  8. $ PosX = rand (0, ($ B _w-$ w_w ));
  9. $ PosY = rand (0, ($ B _h-$ w_h ));

  10. // Create background image resources

  11. $ Back = imagecreatefromjpeg ($ filename );

  12. // Create watermark image resources

  13. $ Water = imagecreatefromgif ($ water );

  14. // Use the imagecopy () function to copy the watermark image to the position specified in the background image.

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

  16. // Save the background image with the watermark

  17. Imagejpeg ($ back, $ filename );
  18. Imagedestroy ($ back );
  19. Imagedestroy ($ water );
  20. }

  21. // Output watermark image

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.