PHP uses GD library to add watermark to the page sample code_PHP tutorial

WBOY
Release: 2016-07-13 10:35:17
Original
997 people have browsed it

Copy code The code is as follows:

header ("Content-type: image/png");
$conn = MYSQL_connect("localhost", "root", ""); //Connect to the database
$colname_rs_article = $_GET['id']; //Get parameter id

mysql_select_db( "cms", $conn); //Execute 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); // Create canvas
$bg = ImageColorAllocate($image, 255, 255, 255); //Set the background to white
ImageFill($image, 0, 0, $bg);
$text_color = ImageColorAllocate( $image, 0, 0, 0); //Set the text color to black
imagestring($image, 5, 0, 0, $row_rs_article['title'], $text_color); //Output the article title
imagestring($image, 3, 0, 20, $row_rs_article['author'], $text_color); //Output article author
imagestring($image, 4, 0, 60, $row_rs_article['content'] , $text_color); //Output article content
$logo = ImageCreateFromPNG('logo.png'); //Get watermark image
$logoW = ImageSX($logo);
$logoH = ImageSY( $logo);
ImageCopy($image, $logo, 0, 0, 0, 0, $logoW, $logoH); //Merge text image and watermark image
ImageJPEG($image); // output to browser
ImageDestroy($logo);
ImageDestroy($image);
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/745209.htmlTechArticleCopy the code as follows: ?php header ("Content-type: image/png"); $conn = MYSQL_connect ("localhost", "root", ""); //Connect to the database $colname_rs_article = $_GET['id']; //Get parameters...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template