Discussion on the method of realizing Chinese watermark in PHP GD library _php Tutorial

Source: Internet
Author: User
Tags image identifier imagejpeg
When we upload images on the site, many of them have the need to add watermarks to the images. Let's give you a detailed explanation

PHP GD Library Implementation of the relevant code examples of Chinese watermark:

  1. < ? PHP
  2. $ im = Imagecreatetruecolor (100,100);
  3. Create a new True color image
  4. $ White = imagecolorallocate ($im, 255,235,255);
  5. assigning colors to an image is different from my design knowledge.
    I never thought that when painting, I want to assign a color to the specified image ID first
    .. This function is often confused with the Imagefill function.
  6. Imagefill ($im, 0,0, $white);
  7. Area fill
  8. $ Black = imagecolorallocate ($im, 250,50,50);
  9. Assign a color to an image
  10. Imagerectangle ($im, 5,5,50,50, $black);
  11. Draw a rectangle
  12. Header ("Content-type:image/jpeg");
  13. Sends the header, with imagejpeg to output the image directly in the browser.
  14. Imagejpeg ($im, ' ImageName ', 100);
  15. Output a image, naming and quality
  16. Imagedestroy ($im);
  17. Releases the memory associated with the image. Image
    Is the image identifier returned by the image creation function
  18. ?>

PHP GD Library Implementation of Chinese watermark code

 
 
  1. < ? PHP
  2. Header ("Content-type:image/png");
  3. /* Notify browser, to output image */
  4. $ im = imagecreate (400, 300);
  5. /* Define the size of the image */
  6. $ Gray = imagecolorallocate ($im, 235, 235, 235);
  7. $ Pink = imagecolorallocate ($im, 255, 128, 255);
  8. /*
  9. $ Fontfile = "C:windowsfontssimhei.ttf" ;
  10. Sorry, this sentence is always adhered to after the submission was lost, do not know what is going on
    , the friends who want to test will comment on the test now
  11. */
  12. /* $fontfile the path to the font, depending on the operating system, can be
    Simhei.ttf (blackbody), Simkai. TTF (in italics),
    Simfang. TTF (imitation), SimSun. TTC (Arial & neo-Arial)
    GD-Supported Chinese fonts */
  13. $ Str = Iconv (' GB2312 ', ' UTF-8 ', ' Chinese watermark!!! ');
  14. /* Convert the gb2312 character set to UTF-8 characters */
  15. Imagettftext ($im, 30, 0, 50, 140,
    $pink, $fontfile, $STR);
  16. /* Add Chinese watermark */
  17. Imagepng ($im);
  18. Imagedestroy ($im);
  19. ?>

The above is the PHP GD library to achieve the Chinese watermark of the relevant methods summary.


http://www.bkjia.com/PHPjc/446046.html www.bkjia.com true http://www.bkjia.com/PHPjc/446046.html techarticle when we upload images on the site, many of them have the need to add watermarks to the images. Below we will give you a detailed explanation of PHP GD Library implementation of the Chinese watermark code example:? php ...

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