注意:ini文件使用php解釋時為注釋文件,什么也沒有輸出,這是為了安全起見而故意為之。而;則是 " /> 91成人免费,一品毛片,香蕉视频黄色软件

一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

php批量縮放圖片的代碼[ini參數(shù)控制]

首先使用一個ini文件來設(shè)置要縮放的大小,其中為寬或高0的則為圖片放大或縮小,都為0則還是原大小,都不為0都拉抻成指定的大小。

注意:ini文件使用php解釋時為注釋文件,什么也沒有輸出,這是為了安全起見而故意為之。而;則是ini文件的注釋。

我設(shè)置的ini文件例子如下:

復(fù)制代碼 代碼如下:
<?php
/*
;Translate the image format using the original image size
[Translation]
width=0
height=0

;Stretch the image to the specified size
[Stretch]
width=800
height=600

;Zoom the image to the specified Width with height auto size
[AutoHeight]
width=740
height=0

;Zoom the image to the specified Height with width auto size
[AutoWidth]
width=0
height=380
*/
?>

下面是編寫的縮放圖片的php代碼,其中變量classes是一個數(shù)組,可以選擇任意多個ini文件中指定的設(shè)置:
復(fù)制代碼 代碼如下:
<?php
$oimg = "test.jpg";//Original image name
$classes = array('Translation','AutoHeight','AutoWidth','Stretch');//Give classes for the new creating images' size which are defined in the specified ini file
$suffix = 'jpg';//The new image's suffix
$inifile = 'image.ini.php';

$size = getimagesize($oimg);
$x = $size[0]/$size[1];
$name = explode('.',$oimg);

if(!file_exists($inifile)) die('Ini file does not exist!');
$cn = parse_ini_file($inifile,true);//Parse the class style image size from ini file
foreach($classes as $class){
foreach($cn as $k=>$v){
if($k==$class){
if($v['width'] && $v['height']){
$thumbWidth = $v['width'];
$thumbHeight = $v['height'];
}elseif($v['width']){
$thumbWidth = $v['width'];
$thumbHeight = round($thumbWidth/$x);
}elseif($v['height']){
$thumbHeight = $v['height'];
$thumbWidth = round($thumbHeight*$x);
}else{
$thumbWidth = $size[0];
$thumbHeight = $size[1];
}
break;
}
}
if(!isset($thumbHeight) && !isset($thumbWidth)) die('Ini file Settings error!');

$nimg = $name[0].'_'.$class.'.'.$suffix;//New image file name
$source = imagecreatefromjpeg($oimg);
$thumb = imagecreatetruecolor($thumbWidth, $thumbHeight);
imagecopyresampled($thumb,$source,0,0,0,0,$thumbWidth,$thumbHeight,$size[0],$size[1]);

if($suffix=='jpg') $method = 'imagejpeg';
else $method='image'.$suffix;
$method($thumb, $nimg);
imagedestroy($thumb);//Release the image source
imagedestroy($source);
}
?>

php技術(shù)php批量縮放圖片的代碼[ini參數(shù)控制],轉(zhuǎn)載需保留來源!

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

主站蜘蛛池模板: 亚洲一区二区三区高清网 | 久久精品免费一区二区三区 | 四虎在线永久免费视频网站 | 伊人小婷婷色香综合缴缴情 | 91麻豆精品国产片在线观看 | 美女扒开双腿让男人爽透视频 | 韩国一级做a爰片性色毛片 韩国一区二区三区 | 国产成人91激情在线播放 | 成年网站未满十八禁毛片免费 | 婷婷激情五月 | 91视频链接| 亚洲视频免费一区 | 2021国产成人午夜精品 | 色就是色欧美图片 | 夜夜穞狠狠穞 | 四虎永久在线观看视频精品 | 色在线视频播放 | 亚洲色四在线视频观看 | 国产午夜亚洲精品不卡福利 | 手机在线观看亚洲国产精品 | 77se77亚洲欧美在线大屁股 | 韩国毛片免费 | 亚洲 图片 小说 欧美 另类 | 高清国产美女在线观看 | 精品午夜久久福利大片免费 | 啪啪伊人网 | 欧美极品美軳人人体 | 五月婷婷综合激情网 | 99久久精品国产麻豆 | 加勒比一本大道在线 | 91大西瓜国产线观看免费 | 国产高清免费午夜在线视频 | 99国产精品免费视频观看 | 色综合合久久天天综合绕视看 | 激情小视频 | 国产美女在线播放 | 成人在线视频免费看 | 一区二区三区免费观看 | 色久在线 | 中国一级特黄真人毛片免费看 | 国产精品女同一区二区久久 |