>  기사  >  백엔드 개발  >  php gd库为页面添加水印实现代码

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

WBOY
WBOY원래의
2016-07-25 08:53:421068검색
  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. ?>
复制代码


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.