PHP functions: Simple picture plus watermark function Code _php Tutorial

Source: Internet
Author: User
Work needs, write a simple is to use the PHP image and watermark function function.
  1. /*
  2. Image plus watermark function
  3. $imag _url as the path to the image to be watermarked
  4. $str the string to be added to the picture
  5. The storage path after $route watermark
  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: $img =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 to the font, depending on the operating system, can be Simhei.ttf (bold), Simkai. TTF (in italics), Simfang. TTF (imitation), SimSun. TTC (Arial & XXFarEastFont-Arial) and other GD-supported Chinese fonts */
  21. $fontfile = "C:windowsfontssimhei.ttf";
  22. $str = Iconv (Gb2312,utf-8, $STR); /* Convert the gb2312 character set to UTF-8 characters */
  23. Imagettftext ($img, 30,0, 0, $pink, $fontfile, $STR);
  24. /* Add Chinese watermark */
  25. Imagepng ($img, $route);
  26. Imagedestroy ($IMG);
  27. }
  28. ?>

The above function wants to be able to have a harvest for everyone.

http://www.bkjia.com/PHPjc/486185.html www.bkjia.com true http://www.bkjia.com/PHPjc/486185.html techarticle work needs, write a simple is to use the PHP image and watermark function function. PHP/* Picture watermark function $imag _url is the path to the image to be watermarked $str the character to be added to the picture ...

  • 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.