PHP watermark Code, PHP translucent watermark support PNG transparent background

Source: Internet
Author: User
Tags unsupported
  1. Original image

  2. $DST = "/upload/20140914/20120914040740-0.jpg"; Picture path

  3. Original picture information

  4. $DST _info = getimagesize ($DST);
  5. Switch ($DST _info[2])
  6. {
  7. Case 1:
  8. $DST _im =imagecreatefromgif ($DST);
  9. Case 2:
  10. $DST _im =imagecreatefromjpeg ($DST);
  11. Case 3:
  12. $DST _im =imagecreatefrompng ($DST);
  13. Case 6:
  14. $DST _im =imagecreatefromwbmp ($DST);
  15. Default
  16. Die ("Unsupported file type 1"); exit;
  17. }
  18. Watermark Image
  19. $SRC = "/images/shuiyin.png"; Note the path to write to
  20. $src _info = getimagesize ($SRC);
  21. Switch ($src _info[2])
  22. {
  23. Case 1:
  24. $SRC _im =imagecreatefromgif ($SRC);
  25. Case 2:
  26. $SRC _im =imagecreatefromjpeg ($SRC);
  27. Case 3:
  28. $SRC _im =imagecreatefrompng ($SRC);
  29. Case 6:
  30. $SRC _im =imagecreatefromwbmp ($SRC);
  31. Default
  32. Die ("Unsupported file type 1"); exit;
  33. }
  34. Translucent format watermark
  35. $alpha = 50; Watermark Transparency
  36. Imagecopymerge ($dst _im, $src _im, $dst _info[0]-$src _info[0]-10, $dst _info[1]-$src _info[1]-10,0,0, $src _info[0],$ SRC_INFO[1], $alpha);
  37. Ways to support PNG's own transparency
  38. Imagecopy ($dst _im, $src _im, $dst _info[0]-$src _info[0]-10, $dst _info[1]-$src _info[1]-10,0,0, $src _info[0], $src _info [1]);

  39. Save picture

  40. Switch ($DST _info[2]) {
  41. Case 1:
  42. Imagegif ($dst _im, $DST);
  43. Case 2:
  44. Imagejpeg ($dst _im, $DST);
  45. Case 3:
  46. Imagepng ($dst _im, $DST);
  47. Case 6:
  48. Imagewbmp ($dst _im, $DST);
  49. Default
  50. Die ("Unsupported file type 2"); exit;
  51. }

  52. Destroying the GD library object

  53. Imagedestroy ($dst _im);
  54. Imagedestroy ($src _im);

Copy Code
  • Related Article

    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.