Phpgd Library adds watermark implementation code to the page

Source: Internet
Author: User
Phpgd Library adds watermark implementation code to the page

  1. Header ("content-type: image/png ");

  2. $ Conn = mysql_connect ("localhost", "root", ""); // connect to the database
  3. $ Colname_rs_article = $ _ get ['id']; // get the parameter id

  4. Mysql_select_db ("cms", $ conn); // execute SQL

  5. $ Query_rs_article = sprintf ("select * from articles where article_id = % s", $ colname_rs_article );
  6. $ Rs_article = mysql_query ($ query_rs_article, $ conn) or die (mysql_error ());
  7. $ Row_rs_article = mysql_fetch_assoc ($ rs_article );
  8. $ Totalrows_rs_article = mysql_num_rows ($ rs_article );

  9. // Create a watermark for the php gd Library

  10. $ Image = imagecreatetruecolor (700,100 0); // Create a canvas
  11. $ Bg = imagecolorallocate ($ image, 255,255,255); // set the background to white.
  12. Imagefill ($ image, 0, 0, $ bg );
  13. $ Text_color = imagecolorallocate ($ image, 0, 0, 0); // set the text color to black.
  14. Imagestring ($ image, 5, 0, 0, $ row_rs_article ['title'], $ text_color); // output the article title
  15. Imagestring ($ image, 3, 0, 20, $ row_rs_article ['author'], $ text_color); // output author
  16. Imagestring ($ image, 4, 0, 60, $ row_rs_article ['content'], $ text_color); // output the article content
  17. $ Logo = imagecreatefrompng('logo.png '); // Obtain the watermark image
  18. $ Logow = imagesx ($ logo );
  19. $ Logoh = imagesy ($ logo );
  20. Imagecopy ($ image, $ logo, 0, 0, 0, 0, $ logow, $ logoh); // merge text images and watermark images
  21. Imagejpeg ($ image); // output to browser
  22. Imagedestroy ($ logo );
  23. Imagedestroy ($ image );
  24. ?>

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.