注意:ini文件使用php解釋時為注釋文件,什么也沒有輸出,這是為了安全起見而故意為之。而;則是 " /> 黄色污污在线观看,99激情,二区久久国产乱子伦免费精品

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

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

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

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

我設置的ini文件例子如下:

復制代碼 代碼如下:
<?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是一個數組,可以選擇任意多個ini文件中指定的設置:
復制代碼 代碼如下:
<?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技術php批量縮放圖片的代碼[ini參數控制],轉載需保留來源!

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

主站蜘蛛池模板: 欧美精品激情 | 欧美另类videosgrstv变态 欧美另类xxx | 91国内视频在线观看 | 国产大陆亚洲精品国产 | 五月婷激情 | 69国产成人精品午夜福中文 | 亚洲成人在线免费观看 | 亚洲首页国产精品丝袜 | 亚洲激情小视频 | 99精品国产成人一区二区 | 日本理论片在线播放 | 国产精品视频自拍 | 色婷婷在线播放 | 亚洲图片欧美文学小说激情 | 大胆gogo999亚洲肉体艺术 | 欧美1314www伊人久久香网 | 久久精品一级 | 理论片中文字幕在线观看 | 成人午夜视频在线观 | 黄色免费观看视频网站 | 日韩在线精品视频 | 美女视频一区二区三区在线 | 精品国产自在现线看 | 久本草在线中文字幕亚洲欧美 | 日日狠狠久久偷偷四色综合免费 | 亚洲欧美激情视频 | 9久9久女女免费精品视频在线观看 | 五月天婷婷色综合 | 久久综合一区二区 | 欧美成人高清手机在线视频 | 一级女毛片 | 国产伦精品一区二区三区免费迷 | 毛片色毛片18毛片美女 | 国产精品美女久久久久网 | 国产男人女人做性全过程视频 | 国产成人+综合亚洲+天堂 | 成 人 黄 色 视频播放165 | 婷婷六月在线 | 久久国产成人精品麻豆 | 黄页视频在线观看 | 亚州激情 |