PHP Add text watermark to image

Source: Internet
Author: User
Tags image identifier

<?php/* the method of adding text watermark to the picture */$dst _path =  ' http://f4.topitme.com/4/15/11/1166351597fe111154l.jpg '; $dst  = imagecreatefromstring (file_get_contents ($DST _path));/*imagecreatefromstring ()--Creates a new image from the image stream in the string, Returns an image identifier that expresses an image Image format from a given string that is 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 image resource returned by the image creation function size to use the font size of the watermark angle (angle) The tilt angle of the text, If the 0 degree represents the text from left to right, if it is 90 degrees from the beginning of the first text of the x, y watermark text, color is the color of the watermark text fontfile, you want to use the path of the TrueType font */list ($dst _w, $dst _h, $dst _ Type)  = getimagesize ($dst _path),/*list (mixed  $varname [, mixed $ ...] --Assigning values in an array to some variables like array (), this is not a real function, but a language structure, and List () assigns a set of variables in one step *//*getimagesize () what information can be obtained? The GetImageSize function returns all information about the image, including size, type, and so on */switch ($dst _type) {    case 1://gif     &nBsp;   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--exporting images to a browser or file in PNG format     imagepng () exports the GD image Stream (image) to the callout output in PNG format (typically a browser) , or if you give the filename with filename, output it to the file */}imagedestroy ($DST); >

Zhongzhiyuan Nanjing 904727147, Jiangsu

PHP Add text watermark to image

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.