首頁  >  文章  >  後端開發  >  acronis true image Php Image Resize圖片大小調整的函數程式碼

acronis true image Php Image Resize圖片大小調整的函數程式碼

WBOY
WBOY原創
2016-07-29 08:44:131218瀏覽

複製程式碼程式碼如下:


function my_image_resize($src_file, $dst_file, $dst_width=32, $dst_ 🎜>if($dst_width echo "參數寬度或高度錯誤!";
退出();
}
if(!file_exists($src_file )) {
echo $src_file . “不存在!”;
退出();
}
$type=exif_imagetype($src_file);
$support_type=array(IMAGETYPE_JPEG, IMAGETY , IMAGETYPE_GIF);
if(!in_array($type, $support_type,true)) {
echo "不支援此類型的圖片!只支援jpg 、 gif 或png";
退出();
}
switch($type) {
case IMAGETYPE_JPEG :
$src_img=imagecreatefromjpeg($src_file);
休息;休息;
案例IMAGETYPE_GIF:
$src_img=imagecreatefromgif($src_file);
休息;
預設:
echo "載入圖片錯誤;"; >退出();
}
$src_w=imagesx($src_img);
$src_h=imagesy($src_img);
$ratio_w=1.0 * $dst_wid/$src_width/$src_wid $ratio_h=1.0 * $dst_height/$src_h;
if ($src_w$x = ($dst_width-$src_w)/2
$x = ($dst_width-$src_w)/2
$y = ($dst_height-$src_h)/2;
$new_img=imagecreatetruecolor($dst_width,$dst_height);
imagecopy($new_img,$src_img,$x,$y,0,0,$ dst_width,$dst_height);
switch($type) {
case IMAGETYPE_JPEG :
imagejpeg($new_img,$dst_file,100);
休息; ($new_img,$dst_file);
休息;
案例IMAGETYPE_GIF:
imagegif($new_img,$dst_file);
休息;
預設:
中斷;
} else {
$dstwh = $dst_width/$dst_height;
$srcwh = $src_w/$src_h;
if ($ratio_oomw dst_width;
$zoom_h = $zoom_w*($src_h/$src_w);
} else {
$zoom_h = $dst_height;
$z_w = $zoomh*($zrc_woom) ;
}
$zoom_img=imagecreatetruecolor($zoom_w, $zoom_h);
imagecopyresampled($zoom_img,$src_img,0,0,0,0,$zoom_w,$zoom_w. );
$new_img=imagecreatetruecolor($dst_width,$dst_height);
$x = ($dst_width-$zoom_w)/2;
$y = ($dst_height-$zoom_w)/2;
$y = ($dst_height-$zoom_h)/2+1 ;
imagecopy($new_img,$zoom_img,$x,$y,0,0,$dst_width,$dst_height);
switch($type) {
case IMAGETYPE_JPEG : 休息;
案例IMAGETYPE_PNG :
imagepng($new_img,$dst_file);
休息;
案例研究$dst_file);
休息;
預設:
中斷;
}
}
}


以上就介紹了acronis true image Php Image Resize圖片大小調整的函數代碼,包括acronis true image方面的內容,希望對PHP教程有興趣的朋友有所幫助。


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn