php 使用GD库为页面增加水印

本文介绍了一种使用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);  
?>



本文章来至源码世界  http://www.ymsky.net/views/52280.shtml

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值