php将图片保存为不同尺寸图片的图片类实例(2)

//获取相应规格的图片地址 //gen=0:保持比例缩放,不剪裁,如高为0,则保证宽度按比例缩放 gen=1:保证长宽,剪裁 function get_spec_image($img_path,$width=0,$height=0,$gen=0,$is_preview=true) { if($width==0) $new_path = $img_path; else { $img_name = substr($img_path,0,-4); $img_ext = substr($img_path,-3); if($is_preview) $new_path = $img_name."_".$width."x".$height.".jpg"; else $new_path = $img_name."o_".$width."x".$height.".jpg"; if(!file_exists($new_path)) { require_once "imagecls.php"; $imagec = new imagecls(); $thumb = $imagec->thumb($img_path,$width,$height,$gen,true,"",$is_preview); if(app_conf("PUBLIC_DOMAIN_ROOT")!='') { $paths = pathinfo($new_path); $path = str_replace("./","",$paths['dirname']); $filename = $paths['basename']; $pathwithoupublic = str_replace("public/","",$path); $file_data = @file_get_contents($path.$file); $img = @imagecreatefromstring($file_data); if($img!==false) { $save_path = "public/".$path; if(!is_dir($save_path)) { @mk_dir($save_path); } @file_put_contents($save_path.$name,$file_data); } } } } return $new_path; }

3.使用方法:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/2df874a38c805393e1af16a616cbf9a8.html