Php> generate thumbnails based on remote image URLs

Source: Internet
Author: User
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;}?>
 

?

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.