Home > Backend Development > PHP Tutorial > PHP gd library adds watermark implementation code to the page

PHP gd library adds watermark implementation code to the page

WBOY
Release: 2016-07-25 08:53:42
Original
1114 people have browsed it
  1. header ("content-type: image/png");

  2. $conn = mysql_connect("localhost", "root", ""); //Connect to the 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 );

    //Set the background to white
  9. imagefill($image, 0, 0, $bg);
  10. $text_color = imagecolorallocate($image, 0, 0, 0); //Set the text color to black
  11. imagestring($image, 5 , 0, 0, $row_rs_article['title'], $text_color); //Output the article title
  12. imagestring($image, 3, 0, 20, $row_rs_article['author'], $text_color); //Output the article Author
  13. imagestring($image, 4, 0, 60, $row_rs_article['content'], $text_color); //Output article content
  14. $logo = imagecreatefrompng('logo.png'); //Get watermark image
  15. $ logow = imagesx($logo);
  16. $logoh = imagesy($logo);
  17. imagecopy($image, $logo, 0, 0, 0, 0, $logow, $logoh); //Merge text images and watermark images
  18. imagejpeg($image); // output to browser
  19. imagedestroy($logo);
  20. imagedestroy($image);
  21. ?>

  22. Copy code
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template