Image generates thumbnails and copyright classes

xiaoxiao2021-03-06  86

http://bulaoge.com/topic.asp?dmn=stone&tid=112 I have seen the PHP's picture processing function in recent days. In the past, the demand for this area is less, and there is nothing, I have time recently. a bit. I feel that some simple features can be, complicated, even if the GD Ku 20.0.1, still does not support Chinese, read a few articles, I want to use Chinese to convert GB2312 to Unicode and write pictures, It's too much trouble, and the sure is only used in English. The image generating portion can define the maximum, wide, and compare the news and albums such as news and albums. GD2.0.1 has great improvement in image processing, I tried imagecopyresized and imagecopyresample, the picture processed by the latter is obviously better than the former, according to the manual, the latter re-sampling of the changed size is basically unhappy, generated The effect of thumbnails is really good. The following is the original image (the original picture is too big.) Http://www.1001w.net/mm.jpg thumbnail plus copyright (using imagecopyResample) after basically no distortion plus copyright (using ImageCopyResize) Distortion is relatively powerful) ---------------------------------------------- --------------- below is class -----------------------

gallerypath = $ gallerypath; $ this-> fontname = $ fontpath. "04b_08 __. TTF";} // =========

===================================================================================================================================================================================== 128) // Function: Generate thumbnails (output to browser) // Parameters: $ sourfile image source file // Parameters: $ width Generates the width of the thumbnail // Parameters: $ HEIGHT Generates the height // of the thumbnail: Return: 0 Returns the generated image path / / ========================================================================================= === Function Makethumb ($ SOURFILE, $ Width = 128, $ height = 128) {$ ImageInfo = $ this-> GetInfo ($ SOLEFILE); $ SOURFILE = $ this-> SourcePath. $ SOURFILE; $ newname = SUBSTR $ imageInfo ["name"], 0, STRPOS ($ ImageInfo ["Name"], ".")). "_thumb.jpg"; switch ($ imageinfo ["type"]) {casse 1: // gif $ img = imagecreatefromgif ($ sourFile); break; case 2: // jpg $ img = imagecreatefromjpeg ($ sourFile); break; case 3: // png $ img = imagecreatefrompng ($ sourFile); break; default: return 0; break } IF (! $ img) Return 0; $ width = ($ Width> $ imageinfo ["width"])? $ imageinfo ["width"]: $ width; $ heiGHT = ($ HEIGHT> $ imageinfo ["Height "])? $ imageinfo [" Height "]: $ heiGHT; $ srcw = $ imageinfo [" width "]; $ srch = $ imageinfo [" height "]; if ($ srcw * $ width> $ srch * $ HEIGHT $ HEIGHT = ROUND ($ srch * $ width / $ srcw); Else $ width = ROUND ($ srcw * $ heiGHT / $ srch); // * if ("ImageCreatetrueColor") //gd2.0.1 {$ new = imagecreatetruecolor ($ width, $ heiGHT); ImageCopyResampled ($ NEW, $ IMG, 0, 0, 0, 0, $ Width, $ HEIGHT, $ ImageInfo ["Width"

} Else {$ new = Imagecreate ($ Width, $ HEIGHT); ImageCopyResized ($ New, $ IMG, 0, 0, 0, 0, $ Width, $ HEIGHT, $ imageInfo ["width"], $ imageInfo ["height"]);} // * / if ($ this-> Tofile) {if (file_exists ($ this-> gallerypath. $ newname) Unlink ($ this-> galleryPath . $ newname; imagejpeg ($ new, $ newname); Return $ this-> gallerypath. $ newname;} else {imagejpeg ($ new); imagedestroy ($ IMG) );} / / ========================================== // function : Watermark ($ SOURFILE, $ TEXT) // Function: Watermark to the Picture: $ SOURFILE Image File Name / / Parameters: $ text text array (including two strings) // Return: 1 Return when successful Generated picture path / / / ================================================== Function Watermark ($ IMAGEINFO = $ THIS-> GetInfo ($ SOURFILE); $ SOURFILE = $ THIS-> SourcePath. $ SOURFILE; $ newname = Substr ($ imageinfo ["name"], 0, Strrpos $ imageInfo ["name"], ".")))). "_mark.jpg"; switch ($ imageinfo ["type"]) {casse 1: // gif $ IMG = imagecreatefromgif ($ SOURFILE); Break; Case 2 : // JPG $ IMG = ImageCreateFromJPEG ($ SOLLE); Break; Case 3: // PNG $ IMG = ImageCreateFromNG ($ SOLLE); Break; default: return 0; Break;} if (! $ img) Return 0; $ width = ($ this-> maxwidth > $ imageInfo ["width"])? $ imageInfo ["width"]: $ this-> maxwidth; $ height = ($ this-> maxheight>

$ imageInfo ["Height"])? $ imageInfo ["Height"]: $ this-> maxheight; $ srcw = $ imageinfo ["width"]; $ srch = $ imageinfo ["height"]; if ($ srcw * $ width> $ srch * $ heiGHT) $ height = ROUND ($ srch * $ width / $ srcw); Else $ width = ROUND ($ srcw * $ heiGHT / $ srch); // * if (Function_exists ("ImageCreatetrueColor" ))) //Gd2.0.1 {$ new = imagecreatetruecolor ($ Width, $ HEIGHT); ImageCopyResampled ($ NEW, $ IMG, 0, 0, 0, 0, $ Width, $ HEIGHT, $ ImageInfo ["Width"], $ imageInfo ["Height"]);} else {$ new = imagecreate ($ Width, $ HEIGHT); ImageCopyResize ($ New, $ IMG, 0, 0, 0, 0, $ Width, $ HEIGHT, $ imageInfo [" Width "], $ imageInfo [" Height "]); NEW, 230, 230, 230, 40); // $ recentw = max (Strlen ($ text [0]), Strlen ($ text [1])) * 7; ImageFilledRectangle ($ New, 0, $ HEIGHT-26 $ Width, $ HEIGHT, $ Alpha); ImagefilledRectangle ($ New, 13, $ HEIGHT-20, 15, $ HEIGHT-7, $ Black); ImageTfText ($ New, 4.9, 0, 20, $ HEIGHT-14, $ black $ THIS-> FontName, $ text [0]); ImagetTftext ($ New, 4.9, 0, 20, $ HEIGHT-6, $ Black, $ this-> fontname, $ text [1]); // * / IF ($ THIS-> Tofile) {IF ($ this-> gallerypath. $ newname)) Unlink ($ this-> gallerypath. $ newname); ImageJpeg ($ new, $ this-> gallerypath. $ newname); Return $ this-> gallerypath. $ newname;} else {imagejpeg ($ new);} imagedestroy ($ new); imagedestroy;} // =============== ===========================

// Function: Displaythumb ($ file) // Function: Display the thumbnail of the specified image // Parameter: $ file file name // Return: 0 pictures do not exist / / ============= ============================= Function Displaythumb ($ file) {$ thumbname = SUBSTR ($ file, 0, strrpos ($ file , ".")). "_thumb.jpg"; $ file = $ this-> gallerypath. $ thumbname; if (! file_exists ($ file)) Return 0; $ html = " "; echo $ html;} // ============================== ============ // Function: DisplayMark ($ file) // function: Show the watermark map of the specified picture // Parameter: $ file file name // Return: 0 pictures do not exist // = ===================================================== = SUBSTR ($ File, 0, StrPos ($ file, ")))." _mark.jpg "; $ file = $ this-> gallerypath. $ markname; if (! file_exists ($ file)) Return 0; $ HTML = ""; echo $ html;} // ================== ===========================00: getInfo ($ file) // function: return image information // Parameter: $ file file path /// Returns: Picture information array / / =========

===============================================00 {$ file = $ this-> sourcepath. $ File; $ data = getImageSize ($ file); $ imageinfo ["width"] = $ data [0]; $ imageInfo ["height"] = $ data [1]; $ imageinfo ["type"] = $ data [ 2]; $ imageInfo ["name"] = basename ($ file); return $ imageinfo;}}?> ------------------------- --------- Here is the use of this class uses a 04B_08 __. TTF font using the class to specify the font path ------------------------------------------------------------------------------------ ----------------- MaxWidth = $ IMG- > Maxheight = 300; $ IMG-> Tofile = true; $ IMG-> Watermark ("mm.jpg", $ text); $ IMG-> Makethumb ("mm.jpg"); $ IMG-> Displaythumb ("mm .jpg "); $ IMG-> DisplayMark (" mm.jpg ");?>

转载请注明原文地址:https://www.9cbs.com/read-106299.html

New Post(0)