$img = ' 22.jpg ';
- $arr =getimagesize ($IMG);
- Print_r ($arr); $arr [0] for the width of the picture, $arr [1] for the height of the picture, $arr [2] for the type of the picture, that is, the extension of the picture,
- Switch ($arr [2]) {
- Case 1:
- $IMGN = Imagecreatefromgif ($img);
- Break
- Case 2:
- $IMGN = Imagecreatefromjpeg ($img);
- Break
- Case 3:
- $IMGN = Imagecreatefrompng ($img);
- Break
- Case 6:
- $IMGN = Imagecreatefromwbmp ($img);
- Break
- Default
- Die ("Unsupported file type");
- Exit
- }
Start the watermark. Ready to play text (PHP text watermark)
- $str = "Text to be printed";
- $str 1 = "Text to be printed";
$str = Iconv ("gb2312", "Utf-8", "Text to be printed"); (This statement is explained at the end);
- Then set the color of the text in the palette:
- $dest =imagecreatetruecolor (100,100);
- $BG = Imagecolorallocate ($IMGN, 255,255,255);
$BG = Imagecolorallocate ($IMGN, 0,0,0);
- PHP5 is unable to know the font of the text, so load the text font, where the Windows comes with the Simhei.ttf bold Word, (before loading the font file copied to the project folder below) as follows:
- Imagettftext ($IMGN, 10,0,20,10, $BG, ' Simhei.ttf ', $str); So you can hit the $str text on the $IMGN.
- Imagettftext ($IMGN, 10,0,20,46, $BG, ' Simhei.ttf ', $str 1);
- Header (' Content-type:image/jpeg ');
- $uploaddir = './image/';
- $thumb _path = './image/'. Date ("Ymd"). ' /';
- if (!is_dir ($uploaddir)) {
- mkdir ($uploaddir, 0777);
- }
- if (!is_dir ($thumb _path)) {
- mkdir ($thumb _path,0777);
- }
- $imgs = $thumb _path.time (). JPG ';
- Imagejpeg ($IMGN, $imgs, ' 80 ');
- echo "";
- : getimagesize, $str = Iconv ("GBK", "Utf-8", "text to be hit"); Describes changing the page's default encoding attribute GBK to UTF-8 International standard encoding. $BG = Imagecolorallocate () sets the foreground text of the picture to White where 0,0,0 represents the component of the red Green blue color, Imagettftext function 12 means the font size 9 indicates the tilt 10,10 the header (' Content-type:image/jpeg ') for the pixel location of the watermark color; Imagejpeg ($IMGN); indicates that the file type of the PHP5 page output is a picture type.
- ?>
Copy Code |