Using imgw.'22.jpg ';
- $ Arr = getimagesize ($ img );
- // Print_r ($ arr); // $ arr [0] indicates the image width, $ arr [1] indicates the image height, and $ arr [2] indicates the image type, that is, the image extension,
- 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 types ");
- Exit;
- }
// Start watermarking. Prepared text (php text watermark)
- $ Str = "text to be printed ";
- $ Str1 = "text to be printed ";
// $ Str = iconv ("gb2312", "UTF-8", "text to be printed"); // (This statement is described at the end );
- // Set the text color with the color palette:
- // $ Dest = imagecreatetruecolor (100,100 );
- $ Bg = imagecolorallocate ($ imgn, 255,255,255 );
// $ Bg = imagecolorallocate ($ imgn, 0, 0 );
- // Php5 cannot know the font of the text, so load the text font. here, load the simhei. ttf italic that comes with windows (copy the font file to the project folder before loading) as follows:
- Imagettftext ($ imgn, 10, 0, 20, 10, $ bg, 'simhei. ttf', $ str); // in this way, the $ str text is hit to $ imgn.
- Imagettftext ($ imgn, 10, 0, 20, 46, $ bg, 'simhei. ttf', $ str1 );
- 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 = effecthumb_path.time().'.jpg ';
- Imagejpeg ($ imgn, $ imgs, '80 ');
- Echo "";
- //: GetImageSize, $ str = iconv ("gbk", "UTF-8", "text to be marked"); this indicates that the default encoding attribute gbk of the page is changed to UTF-8 international standard encoding. $ Bg = imagecolorallocate (): Set the foreground text of the image to white, where 0, 0, and 0 represent the components of the red green blue color, respectively, imagettftext function 12 indicates the font size. 9 indicates a 10-bit tilt. 10 indicates the watermark color. the pixel position header ('content-type: image/jpeg '); imagejpeg ($ imgn ); indicates that the output file type of the php5 page is image.
- ?>
|