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

yipeiwu_com6年前PHP代码库
复制代码 代码如下:

<?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常见错误提示含义解释(实用!值得收藏)

本文讲述了PHP常见错误提示含义解释。分享给大家供大家参考,具体如下: 在学习PHP的时候,经常遇到各种错误提示,今天看到这错误提示和解释感觉挺好,现转过来,供我们学习。呵呵。。。。。...

PhpDocumentor 2安装以及生成API文档的方法

官网地址:http://www.phpdoc.org/项目地址:https://github.com/phpDocumentor/phpDocumentor2 phpDocumentor...

使用PHP批量生成随机用户名

程序一:负责从字典中随机提取数据,写入一个新文件。(1.php) 复制代码 代码如下:<?php /* 从字典文件中提取随机值 */ $file1 =...

用PHP与XML联手进行网站编程代码实例

一、小序    HTML简单易学又通用,一般的PHP程序就是嵌入在HTML语言之中实现的。但是随着WEB越来越广泛的应用,HTML的弱点也越来越明显了。XML的出现,弥补了这些...

PHP流Streams、包装器wrapper概念与用法实例详解

本文实例讲述了PHP流Streams、包装器wrapper概念与用法。分享给大家供大家参考,具体如下: 流Streams这个概念是在php4.3引进的,是对流式数据的抽象,用于统一数据操...