Php thumbnails-PHP source code

Source: Internet
Author: User
Thumbnails php code

 = Self: $ image_h) & (self: $ image_w> $ width) {// scaled back width $ small_w = $ width; // scaled back height $ n = $ width * (self: $ image_h/self: $ image_w); $ small_h = round ($ n );}} // use the source image as the canvas $ a = 'imagecreatefrom '. self: $ image_ext; $ original = $ a ($ image); // create a small canvas $ litter = imagecreatetruecolor ($ width, $ height ); // scale down a large image into the canvas $ x = ($ width-$ small_w)/2; $ y = ($ height-$ small_h)/2; if (! $ Rs = imagecopyresampled ($ litter, $ original, $ x, $ y, $ small_w, $ small_h, self ::$ image_w, self ::$ image_h )) {return false;} // save path $ path = self: image_Dir (). self: rand_Name (). '. '. self: $ image_ext; // save the image $ keep = 'image '. self: $ image_ext; $ keep ($ litter, $ path); // disable image imagedestroy ($ original); imagedestroy ($ litter ); // return path return $ path = strtr ($ path, array (ROOT => '');} // Obtain the image information method protected static function image_Inf O ($ image) {if ($ info = getimagesize ($ image) {// The image width self: $ image_w = $ info [0]; // Image height self: $ image_h = $ info [1]; // Image suffix $ ext = image_type_to_extension ($ info [2]); $ ext = ltrim ($ ext ,'. '); self: $ image_ext = $ ext ;}// generate the path protected static function image_Dir () {$ dir = ROOT. 'data/images /'. date ('Y/m/d/', time (); if (! Is_dir ($ dir) {mkdir ($ dir, 0777, true);} return $ dir;} // random file name protected static function rand_Name () {$ name = str_shuffle ('1234567890qwertyuiopasdfghjklmnbvcxz '); $ name = substr ($ name, 0, 7); return $ name = $ name. '_ smal' ;}}// test // echo Gd_Thumbnail_Tool: mk_thumb('aha. JPG'); // return result: Data/images/2013/02/01/ei3ufpr_smal.jpeg?>

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.