您当前的位置: 首页 > 网站编程 > PHP教程 > php 使用GD库为页面增加水印示例代码

php 使用GD库为页面增加水印示例代码

作者:不详 来源:网络 发布时间: 2014-08-01 09:16 点击:
这篇文章主要介绍了php 使用GD库为页面增加水印的具体实现,需要的朋友可以参考下 代码如下: ?php header (Content-type: image/png); $conn = MYSQL_connect(localhost, root, ); //连接数据库 $colname_rs_article = $_GET['id']; //获取参数id mysql_select_db(cms,

php 使用GD库为页面增加水印示例代码

  这篇文章主要介绍了php 使用GD库为页面增加水印的具体实现,需要的朋友可以参考下

  代码如下:

  <?php

  header ("Content-type: image/png");

  $conn = MYSQL_connect("localhost", "root", ""); //连接数据库

  $colname_rs_article = $_GET['id']; //获取参数id

  mysql_select_db("cms", $conn); //执行SQL

  $query_rs_article = sprintf("SELECT * FROM articles WHERE article_id = %s", $colname_rs_article);

  $rs_article = mysql_query($query_rs_article, $conn) or die(mysql_error());

  $row_rs_article = mysql_fetch_assoc($rs_article);

  $totalRows_rs_article = mysql_num_rows($rs_article);

  $image = ImageCreateTrueColor(700, 1000); //创建画布

  $bg = ImageColorAllocate($image, 255, 255, 255); //设置背景为白色

  ImageFill($image, 0, 0, $bg);

  $text_color = ImageColorAllocate($image, 0, 0, 0); //设置文字颜色为黑色

  imagestring($image, 5, 0, 0, $row_rs_article['title'], $text_color); //输出文章标题

  imagestring($image, 3, 0, 20, $row_rs_article['author'], $text_color); //输出文章作者

  imagestring($image, 4, 0, 60, $row_rs_article['content'], $text_color); //输出文章内容

  $logo = ImageCreateFromPNG('logo.png'); //获得水印图片

  $logoW = ImageSX($logo);

  $logoH = ImageSY($logo);

  ImageCopy($image, $logo, 0, 0, 0, 0, $logoW, $logoH); //合并文字图片与水印图片

  ImageJPEG($image); // output to browser

  ImageDestroy($logo);

  ImageDestroy($image);

  ?>
分享到:
本文"php 使用GD库为页面增加水印示例代码"由远航站长收集整理而来,仅供大家学习与参考使用。更多网站制作教程尽在远航站长站。
顶一下
(0)
0%
踩一下
(0)
0%
[点击 次] [返回上一页] [打印]
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 密码: 验证码:
关于本站 - 联系我们 - 网站声明 - 友情连接- 网站地图 - 站点地图 - 返回顶部
Copyright © 2007-2013 www.yhzhan.com(远航站长). All Rights Reserved .
远航站长:为中小站长提供最佳的学习与交流平台,提供网页制作与网站编程等各类网站制作教程.
官方QQ:445490277 网站群:26680406 网站备案号:豫ICP备07500620号-4