生成缩略图PHP批量生成缩略图的代码

生成缩略图PHP批量生成缩略图的代码

内容导读

收集整理的这篇技术教程文章主要介绍了生成缩略图PHP批量生成缩略图的代码,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1601字,纯文字阅读大概需要3分钟

内容图文

缺点:长宽不一的图片会被拉伸变形,不能智能裁切,需要智能裁切的,请自行研究。
$config = array();
$config['path'] = "./";
$config['t_width'] = 120;
$config['t_height'] = 98;
$config['ignore'] = array("",".","..");
$config['prefix'] = "thumb_";
$done = 0;
define("IMAGE_JPG", 2);
define("ENDL", "n");
if($handle = opendir($config['path'])) {
while(false !== ($file = readdir($handle))) {
if(!array_search($file,$config['ignore'])) {
list($im_width, $im_height, $type) = getimagesize($file);
if($type != IMAGE_JPG) {
continue;
}
$op .= "found -> $file" . ENDL;
$im = @imagecreatefromjpeg($file);
if(!$im) {
$op .= "fail -> couldn't create sour image pointer." . ENDL;
continue;
}
if(file_exists($config['prefix'] . $file) || substr($file, 0, strlen($config['prefix'])) == $config['prefix']) {
$op .= "note -> this file has already got a thumbnail." . ENDL;
continue;
}
$to = imagecreatetruecolor($config['t_width'],$config['t_height']);
if(!$to) {
$op .= "fail -> couldn't create dest image pointer." . ENDL;
continue;
}
if(!imagecopyresampled($to, $im, 0, 0, 0, 0, $config['t_width'], $config['t_height'], $im_width, $im_height)) {
$op .= "fail -> couldn't create thumbnail. php fail." . ENDL;
continue;
}
//保存文件
imagejpeg($to, $config['prefix'] . $file);
$op .= "done -> created thumb: {$config['prefix']}{$file}" . ENDL;
$done++;
}
}
}
closedir($handle);
$op .= "fin -> {$done} file(s) written" . ENDL;
echo "
";

echo $op;
echo "
";
exit;
?>

以上就介绍了生成缩略图 PHP批量生成缩略图的代码,包括了生成缩略图方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

内容总结

以上是为您收集整理的生成缩略图PHP批量生成缩略图的代码全部内容,希望文章能够帮你解决生成缩略图PHP批量生成缩略图的代码所遇到的程序开发问题。 如果觉得技术教程内容还不错,欢迎将网站推荐给程序员好友。

内容备注

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。


本文关键词:

联系我们

在线咨询:点击这里给我发消息

邮件:w420220301@qq.com