四虎精品视频-四虎精品成人免费网站-四虎黄色网-四虎国产视频-国产免费91-国产蜜臀97一区二区三区

Php Image Resize圖片大小調整的函數代碼

復制代碼 代碼如下:
function my_image_resize($src_file, $dst_file, $dst_width=32, $dst_height=32) {
if($dst_width <1 || $dst_height <1) {
echo "params width or height error !";
exit();
}
if(!file_exists($src_file)) {
echo $src_file . " is not exists !";
exit();
}

$type=exif_imagetype($src_file);
$support_type=array(IMAGETYPE_JPEG , IMAGETYPE_PNG , IMAGETYPE_GIF);

if(!in_array($type, $support_type,true)) {
echo "this type of image does not support! only support jpg , gif or png";
exit();
}

switch($type) {
case IMAGETYPE_JPEG :
$src_img=imagecreatefromjpeg($src_file);
break;
case IMAGETYPE_PNG :
$src_img=imagecreatefrompng($src_file);
break;
case IMAGETYPE_GIF :
$src_img=imagecreatefromgif($src_file);
break;
default:
echo "Load image error!";
exit();
}
$src_w=imagesx($src_img);
$src_h=imagesy($src_img);
$ratio_w=1.0 * $dst_width/$src_w;
$ratio_h=1.0 * $dst_height/$src_h;
if ($src_w<=$dst_width && $src_h<=$dst_height) {
$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);
break;
case IMAGETYPE_PNG :
imagepng($new_img,$dst_file);
break;
case IMAGETYPE_GIF :
imagegif($new_img,$dst_file);
break;
default:
break;
}
} else {
$dstwh = $dst_width/$dst_height;
$srcwh = $src_w/$src_h;
if ($ratio_w <= $ratio_h) {
$zoom_w = $dst_width;
$zoom_h = $zoom_w*($src_h/$src_w);
} else {
$zoom_h = $dst_height;
$zoom_w = $zoom_h*($src_w/$src_h);
}

$zoom_img=imagecreatetruecolor($zoom_w, $zoom_h);
imagecopyresampled($zoom_img,$src_img,0,0,0,0,$zoom_w,$zoom_h,$src_w,$src_h);
$new_img=imagecreatetruecolor($dst_width,$dst_height);
$x = ($dst_width-$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 :
imagejpeg($new_img,$dst_file,100);
break;
case IMAGETYPE_PNG :
imagepng($new_img,$dst_file);
break;
case IMAGETYPE_GIF :
imagegif($new_img,$dst_file);
break;
default:
break;
}
}
}

php技術Php Image Resize圖片大小調整的函數代碼,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 念念相忘电影免费观看| 挠胳肢窝肚子腰| 吻胸捏胸揉视频大全| 离歌吉他谱| 性感瑜伽| 刘淑华| 迷失美剧| 相信我们会创造奇迹的歌词| 河东狮吼 电视剧| 日本大片网址| 乔什布洛林| 丁莹| 挠丝袜| 吴爱玲| 一江春水向东流电影| 齐力电影| 人蛇大战 电影| 寡妇激情毛片免费视频| xxoo电影| 薄冰电视剧| 韩国一级免费| 延禧| 无耻之徒阿曼达| bob hartman| 孤独感拉满的头像| 韩国电影色即是空| 推普周主题班会活动记录| 欧美比基尼美女| 高钧贤| 《东北警察故事2》大结局| 浙江卫视奔跑吧官网| 发型男2024流行发型图片| 以一当百| 家书1000字| 有关动物的成语| 军犬麦克斯| 被囚禁的女孩大结局| 红色诗集手抄报简单又漂亮| 岑建勋| 可爱的萝拉| 国生小百合|