Methods for implementing Chinese watermarks in php gd library

Source: Internet
Author: User
Tags image identifier imagejpeg

When we upload images on a website, many users need to add watermarks to images. Next we will explain in detail

Sample Code for implementing a Chinese watermark in the php gd library:

  1. <? Php
  2. $ Im = imagecreatetruecolor (100,100 );
  3. // Create a true color image
  4. $ White = imagecolorallocate ($ im, 255,235,255 );
  5. // Assign color to an image, which is different from my design knowledge ..
    I have never thought of assigning colors to the specified image logo during painting.
    .. This function is often mixed with the imagefill function.
  6. Imagefill ($ im, 0, 0, $ white );
  7. // Fill the area
  8. $ Black = imagecolorallocate ($ im, 250,50, 50 );
  9. // Assign color to an image
  10. Imagerectangle ($ im, 5, 5, 50, 50, $ black );
  11. // Draw a rectangle
  12. Header ("Content-type: image/jpeg ");
  13. // Send the header and use imagejpeg to directly output the image in the browser.
  14. Imagejpeg ($ im, 'imagename', 100 );
  15. // Output an image name and quality
  16. Imagedestroy ($ im );
  17. // Release the memory associated with the image. Image
    Is the image identifier returned by the image creation function.
  18. ?>

Implement Chinese watermark code in php gd library

 
 
  1. <? Php
  2. Header ("Content-type: image/png ");
  3. /* Notify the browser to output the image */
  4. $ Im = imagecreate (400,300 );
  5. /* Define the image size */
  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 stuck and lost after submission. I don't know what's going on.
    The comments to be tested are now tested.
  11. */
  12. /* $ Fontfile font path, depending on the operating system, can be
    Simhei. ttf (), SIMKAI. TTF (),
    SIMFANG. TTF (), SIMSUN. TTC (&)
    Chinese fonts supported by GD */
  13. $ Str = iconv ('gb2312', 'utf-8', 'Chinese watermark !!! ');
  14. /* Convert the gb2312 character set to the UTF-8 Character Set */
  15. ImageTTFText ($ im, 30, 0, 50,140,
    $ Pink, $ fontfile, $ str );
  16. /* Add a Chinese watermark */
  17. Imagepng ($ im );
  18. ImageDestroy ($ im );
  19. ?>

The above is a summary of the methods for implementing Chinese watermarks in the php gd library.


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.