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?>