This article will share with you how to add watermarks to images using php, which is very detailed and comprehensive. For more information, see. The comments are very detailed, so there is not much nonsense here.
<? Php/* Add a text watermark to an image */$ dst_path =' http://f4.topitme.com/4/15/11/1166351597fe111154l.jpg '; $ Dst = imagecreatefromstring (file_get_contents ($ dst_path);/* imagecreatefromstring () -- creates an image from the image stream in the string and returns an image identifier, it indicates that the image format obtained from the given string will be automatically monitored, as long as php supports jpeg, png, gif, wbmp, gd2. */$ font = '. /t1.ttf '; $ black = imagecolorallocate ($ dst, 0, 0, 0); imagefttext ($ dst, 20, 0, 10, 30, $ black, $ font, 'Hello world! ');/* Imagefttext ($ img, $ size, $ angle, $ x, $ y, $ color, $ fontfile, $ text) $ img the font size of the watermark to be used for the image resource size returned by the image creation function angle (angle) text skew angle. if it is 0 degrees, it indicates that the text is left to right, if it is 90 degrees, the starting position of the first text of the y watermark text is from top to bottom. color is the color of the watermark text fontfile, path */list ($ dst_w, $ dst_h, $ dst_type) = getimagesize ($ dst_path);/* list (mixed $ varname [, mixed $ ......]) -- assign values in the array to some variables like array (). This is not a real function, but a language structure, List () assign a value to a group of variables in one step * // * what information can be obtained by getimagesize? The getimagesize function returns all information about the image, including the size, type, and so on. */switch ($ dst_type) {case 1: // GIF header ("content-type: image/gif "); imagegif ($ dst); break; case 2: // JPG header (" content-type: image/jpeg "); imagejpeg ($ dst ); break; case 3: // PNG header ("content-type: image/png"); imagepng ($ dst); break; default: break; /* imagepng -- output the image to the browser or file imagepng () in PNG format. the GD image stream (image) is output to the annotation output in png format (usually the browser ), or, if filename is used to provide a file name, output it to the file */} imagedestroy ($ Dst);?>
The above is all the content of this article. I hope you will like it.