一款php批量生成缩略图代码_PHP教程
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了一款php批量生成缩略图代码_PHP教程,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2256字,纯文字阅读大概需要4分钟。
内容图文
![一款php批量生成缩略图代码_PHP教程](/upload/InfoBanner/zyjiaocheng/181/a57e2107d18741a9979ff8f06d2fbae2.jpg)
$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代码,其中变量classes是一个数组,可以选择任意多个ini文件中指定的设置:
这是一个ini配置文件,上面的代码就要读取这个文件中的图片位置,可以多个。
;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
*/ ?>
注意:ini文件使用php解释时为注释文件,什么也没有输出,这是为了安全起见而故意为之。而;则是ini文件的注释。
http://www.bkjia.com/PHPjc/632987.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/632987.htmlTechArticle?php教程 $oimg = test.jpg;//original image name $classes = array('translation','autoheight','autowidth','stretch');//give classes for the new creating images' size which are defi...
内容总结
以上是互联网集市为您收集整理的一款php批量生成缩略图代码_PHP教程全部内容,希望文章能够帮你解决一款php批量生成缩略图代码_PHP教程所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。