This article describes how to add a watermark to a page using the GD Library in php. For more information, see
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 the 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,100 0); // Create a 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 author
Imagestring ($ image, 4, 0, 60, $ row_rs_article ['content'], $ text_color); // output the article content
$ Logo = ImageCreateFromPNG('logo.png '); // Obtain the watermark image
$ LogoW = ImageSX ($ logo );
$ LogoH = ImageSY ($ logo );
ImageCopy ($ image, $ logo, 0, 0, 0, 0, $ logoW, $ logoH); // merge text images and watermark images
ImageJPEG ($ image); // output to browser
ImageDestroy ($ logo );
ImageDestroy ($ image );
?>