<? Php /* PHP add text watermark class V1.0 Author: Yu Tiedun Mail box: Modified on: Supported image formats: gif, jpg, and png Adjust the watermark position as needed If the modification is better, please send me a copy. */ Class WaterPrint { // Starts the class Public $ text, $ color, $ size, $ font, $ angle, $ px, $ py, $ im; // Text to be added Public function GetWpText ($ text) { $ This-> text = $ text; } // Add text color Public function GetFtColor ($ color) { $ This-> color = $ color; } // Add text font Public function GetFtType ($ font) { $ This-> font = $ font; } // Add the text size Public function GetFtSize ($ size) { $ This-> size = $ size; } // Text rotation angle Public function GetTtAngle ($ angle) { $ This-> angle = $ angle; } // Add text position Public function GetTtPosit () { $ This-> px = 10; $ This-> py = imagesy ($ this-> im)-20; } // Add a text watermark Public function AddWpText ($ pict) { $ Ext = exif_imagetype ($ pict ); Switch ($ ext ){ Case 1: $ Picext = "gif "; $ This-> im = imagecreatefromgif ($ pict ); Break; Case 2: $ Picext = "jpg "; $ This-> im = imagecreatefromjpeg ($ pict ); Break; Case 3: $ Picext = "png "; $ This-> im = imagecreatefrompng ($ pict ); Break; Default: $ This-> Errmsg ("unsupported file format! "); Break; } // $ This-> picext = $ picext; $ This-> GetTtPosit (); $ Im = $ this-> im; $ Size = $ this-> size; $ Angle = $ this-> angle; $ Px = $ this-> px; $ Py = $ this-> py; $ Color = $ this-> color; $ Font = $ this-> font; $ Text = $ this-> text; $ Color = imagecolorallocate ($ im, 255, 0, 0 ); Imagettftext ($ im, $ size, $ angle, $ px, $ py, $ color, $ font, $ text ); Switch ($ picext ){ Case "gif ": Imagegif ($ im, $ pict ); Break; Case "jpg ": Imagejpeg ($ im, $ pict, 100 ); Break; Case "png ": Imagealphablending ($ im, false ); Imagesavealpha ($ im, true ); Imagepng ($ im, $ pict ); Break; } Imagedestroy ($ im ); } // Error message prompt Public function Errmsg ($ msg) { Echo "<script language = 'javascript '> alert ('". $ msg. "'); </script> "; } // End the class } ?> |