PHP縮圖類

來源:互聯網
上載者:User
0 && $countP==$countW && $countW==$countH) {//遍曆一個數組,產生多張縮圖$reArr = array();foreach ($thumb_prefix_arr as $key=>$value){//產生空白畫布並填充顏色$image = imagecreatetruecolor($thumb_width_arr[$key], $thumb_height_arr[$key]);$color = imagecolorallocate($image, 255, 255, 255);//白色imagefill($image, 0, 0, $color);//計算出縮減比例$width_scale = $imgArr['width']/$thumb_width_arr[$key];//寬比$height_scale = $imgArr["height"]/$thumb_height_arr[$key];//高比$scale = $width_scale>$height_scale ? $width_scale : $height_scale;//計算縮圖寬高$width = $imgArr["width"]/$scale;$height = $imgArr["height"]/$scale;//到靶心圖表片的位置$dst_x = ($thumb_width_arr[$key]-$width)/2;$dst_y = ($thumb_height_arr[$key]-$height)/2;//擷取原始圖片資源並拷貝$src_image = $imgArr["createFunName"]($sPath);//擷取原始圖片資源imagecopyresized($image, $src_image, $dst_x, $dst_y, 0, 0, $width, $height, $imgArr["width"], $imgArr["height"]);//儲存並傳回值$re = $imgArr['saveFunName']($image,self::$thumb_savePath.'/'.$thumb_prefix_arr[$key].$imgArr['name']);$reArr[$key] = $re;}//銷毀縮圖資源及原圖片資源,釋放記憶體imagedestroy($image);imagedestroy($src_image);return $reArr;//返回數組}else{return false;}}else{return false;}}protected static function getImageInfo($path){if (is_file($path)) {$imgArr = getimagesize($path);if (is_array($imgArr)) {//如果$imgArr是一個數組,則說明$path是一個真實圖片//判斷不同的圖片類型,使用變數函數,產生圖片資源:$createFunName,儲存圖片資源:$saveFunNameswitch ($imgArr['mime']){case 'image/jpeg':case 'image/pjpeg':$createFunName = 'imagecreatefromjpeg';$saveFunName = 'imagejpeg';break;case 'image/png':$createFunName = 'imagecreatefrompng';$saveFunName = 'imagepng';break;case 'image/gif':$createFunName = 'imagecreatefromgif';$saveFunName = 'imagegif';break;default:return false;}//擷取原圖片名稱$oldName = pathinfo($path,PATHINFO_BASENAME);//返回圖片資訊數組return array('name'=>$oldName,'type'=>$imgArr['mime'],'width'=>$imgArr[0],'height'=>$imgArr[1],'createFunName'=>$createFunName,'saveFunName'=>$saveFunName);}}else{return false;}}}
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.