PHP GD Library to add watermark implementation code to the page

Source: Internet
Author: User
  1. Header ("Content-type:image/png");

  2. $conn = mysql_connect ("localhost", "root", ""); Connecting to a database
  3. $colname _rs_article = $_get[' id ']; Get 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. PHP GD Library Create watermark

  10. $image = Imagecreatetruecolor (700, 1000); 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 text color to Black
  14. Imagestring ($image, 5, 0, 0, $row _rs_article[' title '), $text _color); Output article title
  15. Imagestring ($image, 3, 0, $row _rs_article[' author '), $text _color); Output article author
  16. Imagestring ($image, 4, 0, $row _rs_article[' content '), $text _color); Output article content
  17. $logo = imagecreatefrompng (' logo.png '); Get watermark Picture
  18. $logow = Imagesx ($logo);
  19. $logoh = Imagesy ($logo);
  20. Imagecopy ($image, $logo, 0, 0, 0, 0, $logow, $logoh); Merge text picture with watermark picture
  21. Imagejpeg ($image); Output to Browser
  22. Imagedestroy ($logo);
  23. Imagedestroy ($image);
  24. ?>

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