php gd库为页面添加水印实现代码

WBOY
Freigeben: 2016-07-25 08:53:42
Original
1073 Leute haben es durchsucht
  1. header ("content-type: image/png");

  2. $conn = mysql_connect("localhost", "root", ""); //连接数据库
  3. $colname_rs_article = $_get['id']; //获取参数id
  4. mysql_select_db("cms", $conn); //执行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库创建水印

  10. $image = imagecreatetruecolor(700, 1000); //创建画布
  11. $bg = imagecolorallocate($image, 255, 255, 255); //设置背景为白色
  12. imagefill($image, 0, 0, $bg);
  13. $text_color = imagecolorallocate($image, 0, 0, 0); //设置文字颜色为黑色
  14. imagestring($image, 5, 0, 0, $row_rs_article['title'], $text_color); //输出文章标题
  15. imagestring($image, 3, 0, 20, $row_rs_article['author'], $text_color); //输出文章作者
  16. imagestring($image, 4, 0, 60, $row_rs_article['content'], $text_color); //输出文章内容
  17. $logo = imagecreatefrompng('logo.png'); //获得水印图片
  18. $logow = imagesx($logo);
  19. $logoh = imagesy($logo);
  20. imagecopy($image, $logo, 0, 0, 0, 0, $logow, $logoh); //合并文字图片与水印图片
  21. imagejpeg($image); // output to browser
  22. imagedestroy($logo);
  23. imagedestroy($image);
  24. ?>
复制代码


Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!