注意:ini文件使用php解釋時為注釋文件,什么也沒有輸出,這是為了安全起見而故意為之。而;則是 " /> 精品欧美视频,免费成人av网站,日韩av成人

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

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參數控制],轉載需保留來源!

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

主站蜘蛛池模板: 我的英雄学院第三季| 美女撒尿视频| 女生被艹网站| 好好说再见电影| 任港秀| 《伪装者》演员| 大奉打更人电视剧在线| 真实游戏在线| 有关动物的成语| 范冰冰激情片段| 汪汪队完整版全集免费| 变形记开头结尾优美段落| 水蜜桃蜜桃在线观看| 《stag》电影在线观看| 八月照相馆| 日本大片ppt免费ppt2024| 包公决战潘金莲| 肚兜电影| 心跳源计划演员表| 查隆拉·诺山荣| 阿莫西林原研药| 茉莉2| 香谱七十二法图大全| 娇喘视频在线观看| 各各他的路赞美诗歌| 都市频道今日节目表| 韩绛| 中国古代寓言阅读记录卡| 宇宙刑事卡邦| 高一英语单词表电子版| 浪人街| 《遇见你之后》电影在线观看| 按摩服务电影| 按摩私处| 秀人网门户首页| 暗夜尖叫1988美国版高清观看| 胡家玮| 电影《追求》| 端午给老板祝福简短句| 二十以内加减法口诀表| 爱情洗牌|