现在的位置: 首页php实例>正文
使用GD库添加水印  
发表于551 天前 php实例 评论关闭

php如何使用GD库添加水印呢?

使用GD库添加水印的步骤如下:

1、创建一个透明的图片,不能对www.phpdo.net 有任何的遮挡;

2、将这张图像放置在页面上。

例如:

<?php
header("Content-type:image/png");
$conn = mysql_connect("localhost","root","");
$colname_rs_article = $_GET['id'];
mysql_select_db("cms",$conn);
$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);
imagedestroy($logo);
imagedestroy($image);
?>
【上篇】
【下篇】

报歉!评论已关闭.

不想听你唠叨×