PHP watermark code, PHP translucent watermark supports png transparent background

WBOY
Release: 2016-07-25 08:51:51
Original
2339 people have browsed it
  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);break;
  9. case 2:
  10. $dst_im =imagecreatefromjpeg($dst) ;break;
  11. case 3:
  12. $dst_im =imagecreatefrompng($dst);break;
  13. case 6:
  14. $dst_im =imagecreatefromwbmp($dst);break;
  15. default:
  16. die("Unsupported file type 1") ;exit;
  17. }
  18. //Watermark image
  19. $src = "/images/shuiyin.png"; //Note that the path must be written correctly
  20. $src_info = getimagesize($src);
  21. switch ($src_info[2])
  22. {
  23. case 1:
  24. $src_im =imagecreatefromgif($src);break;
  25. case 2:
  26. $src_im =imagecreatefromjpeg($src);break;
  27. case 3:
  28. $src_im =imagecreatefrompng($src);break;
  29. case 6:
  30. $src_im =imagecreatefromwbmp($src);break;
  31. default:
  32. die("Unsupported file type 1");exit;
  33. }
  34. //Semi-transparent 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. //How to support the transparency of png itself
  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 the picture

  40. switch ($dst_info[2]){
  41. case 1:
  42. imagegif($dst_im,$dst);break;
  43. case 2:
  44. imagejpeg($dst_im,$dst);break;
  45. case 3:
  46. imagepng($dst_im,$dst);break;
  47. case 6:
  48. imagewbmp($dst_im,$dst);break;
  49. default:
  50. die("Unsupported file type 2");exit;
  51. }

  52. //Destroy the gd library object

  53. imagedestroy($dst_im);
  54. imagedestroy($src_im);

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!