PHP function: Simple picture watermark function code_PHP tutorial

WBOY
Release: 2016-07-13 17:40:49
Original
742 people have browsed it

For work needs, I wrote a simple PHP image watermarking function.

  1. /*
  2. Image watermarking function
  3. $imag_url is the path to the image to be watermarked
  4. $str is the string to be added to the picture
  5. $route is the storage path after watermarking
  6. */
  7. function watermark($ imag_url,$str,$route) {
  8. $type_array=explode(.,$imag_url);
  9. $imag_type=$type_array[count($type_array)-1];
  10. switch($imag_type) {
  11. case gif: $img=imagecreatefromgif($imag_url); break;
  12. case jpeg: $img=imagecreatefromjpeg($imag_url); break;
  13. case jpg: $img=imagecreatefromjpeg($imag_url); break;
  14. case png: $img=imagecreatefrompng($imag_url); break;
  15. default: $im g= imagecreatefromgif($imag_url); break;
  16. }
  17. //Font color
  18. $gray = imagecolorallocate($img, 235, 235, 235);
  19. $pink = imagecolorallocate($img, 255, 128, 255);
  20. /* $fontfile The path of the font, depending on the operating system, can be simhei.ttf (black body), SIMKAI.TTF( Chinese fonts supported by GD*/
  21. $fontfile = "C:WINDOWSFontsSIMHEI.TTF";
  22. $str = iconv(GB2312,UTF-8,$str); /*Convert gb2312 character set to UTF-8 characters*/
  23. imagettftext($img, 30,0, 0, 200, $pink, $fontfile, $str);
  24. /* Add Chinese watermark*/
  25. imagepng($img,$route);
  26. imagedestroy($img);
  27. }
  28. ?>

I hope the above function can be useful to everyone.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486185.htmlTechArticleFor work needs, I wrote a simple PHP image watermarking function. ?php /* Image watermarking function $imag_url is the path of the image to be watermarked $str is the character to be added to the image...
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!