;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
- */ ?>
2、缩放图片的php代码
变量classes是一个数组,可以选择任意多个ini文件中指定的设置。
- /**
- * 批量绽放图片
- * edit bbs.it-home.org
- * at 2013/5/15
- */
- $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也能做到。
>>> 您可能感兴趣的文章:
php缩放图片的实例代码
php等比例缩放图片的示例参考
php等比例缩放图片的工具SimpleImage实例学习 |