Thumbnails generated by PHP

Source: Internet
Author: User
& Lt ;? Php *** generate a thumbnail ** @ authoryangzhiguo0903@163.com * @ paramstring source image absolute complete address {with file name and suffix name} * @ paramstring target Image absolute complete address {with file name and suffix name} * @ paramint thumbnail width {0: the target height cannot be
 $ Src_w & $ height> $ src_h) | ($ height> $ src_h & $ width = 0) | ($ width> $ src_w & $ height = 0) {$ proportion = 1;} if ($ width> $ src_w) {$ dst_w = $ width = $ src_w;} if ($ height> $ src_h) {$ dst_h = $ height = $ src_h;} if (! $ Width &&! $ Height &&! $ Proportion) {return false;} if (! $ Proportion) {if ($ cut = 0) {if ($ dst_w & $ dst_h) {if ($ dst_w/$ src_w> $ dst_h/$ src_h) {$ dst_w = $ src_w * ($ dst_h/$ src_h); $ x = 0-($ dst_w-$ width)/2 ;} else {$ dst_h = $ src_h * ($ dst_w/$ src_w); $ y = 0-($ dst_h-$ height)/2 ;}} else if ($ dst_w xor $ dst_h) {if ($ dst_w &&! $ Dst_h) // Has width and height {$ propor = $ dst_w/$ src_w; $ height = $ dst_h = $ src_h * $ propor;} else if (! $ Dst_w & $ dst_h) // high and no width {$ propor = $ dst_h/$ src_h; $ width = $ dst_w = $ src_w * $ propor ;}}} else {if (! $ Dst_h) // no height during cropping {$ height = $ dst_h = $ dst_w;} if (! $ Dst_w) // no width during cropping {$ width = $ dst_w = $ dst_h;} $ propor = min (max ($ dst_w/$ src_w, $ dst_h/$ src_h ), 1); $ dst_w = (int) round ($ src_w * $ propor); $ dst_h = (int) round ($ src_h * $ propor ); $ x = ($ width-$ dst_w)/2; $ y = ($ height-$ dst_h)/2 ;}} else {$ proportion = min ($ proportion, 1); $ height = $ dst_h = $ src_h * $ proportion; $ width = $ dst_w = $ src_w * $ proportion;} $ src = $ createfun ($ src_img); $ dst = Imagecreatetruecolor ($ width? $ Width: $ dst_w, $ height? $ Height: $ dst_h); $ white = imagecolorallocate ($ dst, 255,255,255); imagefill ($ dst, 0, 0, $ white); if (function_exists ('imagecopyresampled ')) {imagecopyresampled ($ dst, $ src, $ x, $ y, 0, 0, $ dst_w, $ dst_h, $ src_w, $ src_h);} else {imagecopyresized ($ dst, $ src, $ x, $ y, 0, 0, $ dst_w, $ dst_h, $ src_w, $ src_h);} $ otfunc ($ dst, $ dst_img ); imagedestroy ($ dst); imagedestroy ($ src); return true ;}

function fileext($file){    return pathinfo($file, PATHINFO_EXTENSION);}

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.