Php & gt; generate thumbnails based on the remote image URL & lt ;? Php *** function: adjust the Image size or generate a thumbnail * modification: 2013-2-15 * return: TrueFalse * parameter: * $ Image (including path) * $ Dw450: Max width when adjusting; absolute width when thumbnails * $ Dh450: Max height when adjusting; absolute height when thumbnails * php> generate a thumbnail based on the remote image URL
$ Dw) {$ Par = $ Dw/$ width; $ width = $ Dw; $ height = $ height * $ Par; IF ($ height> $ Dh) {$ Par = $ Dh/$ height; $ height = $ Dh; $ width = $ width * $ Par;} ElseIF ($ height> $ Dh) {$ Par = $ Dh/$ height; $ height = $ Dh; $ width = $ width * $ Par; IF ($ width> $ Dw) {$ Par = $ Dw/$ width; $ width = $ Dw; $ height = $ height * $ Par ;}} Else {$ width = $ width; $ height = $ height ;}$ nImg = ImageCreateTrueColor ($ width, $ height); // create a true color canvas ImageCopyReSampled ($ nImg, $ Img, $ width, $ height, $ W, $ h); // re-sample and copy some images and resize ImageJpeg ($ nImg, $ Image ); // return true to the browser or file in JPEG format;} Else {// $ w = ImagesX ($ Img) for generating thumbnails ); $ h = ImagesY ($ Img); $ width = $ w; $ height = $ h; $ nImg = ImageCreateTrueColor ($ Dw, $ Dh ); IF ($ h/$ w> $ Dh/$ Dw) {// The height is relatively large $ width = $ Dw; $ height = $ h * $ Dw/$ w; $ IntNH = $ height-$ Dh; ImageCopyReSampled ($ nImg, $ Img, 0,-$ IntNH/1.8, 0, 0, $ Dw, $ height, $ w, $ h);} Else {// The width is relatively large $ height = $ Dh; $ width = $ w * $ Dh/$ h; $ IntN W = $ width-$ Dw; ImageCopyReSampled ($ nImg, $ Img,-$ IntNW/1.8, 0, 0, $ width, $ Dh, $ w, $ h );} imageJpeg ($ nImg, $ Image); return true ;}}; /*** obtain the image on the server based on the url * $ url server slice path $ filename File Name */function GrabImage ($ url, $ filename = "") {if ($ url = "") return false; if ($ filename = "") {$ ext = strrchr ($ url ,". "); if ($ ext! = ". Gif" & $ ext! = ". Jpg" & $ ext! = ". Png ") return false; $ filename = date (" YmdHis "). $ ext;} ob_start (); readfile ($ url); $ img = ob_get_contents (); ob_end_clean (); $ size = strlen ($ img ); [email protected] ($ filename, "a"); fwrite ($ fp2, $ img); fclose ($ fp2); return $ filename;}?>
?