php缩略图生成会模糊不,PHP_PHP批量生成缩略图的代码,缺点:长宽不一的图片会被拉 - phpStudy...

PHP批量生成缩略图的代码

缺点:长宽不一的图片会被拉伸变形,不能智能裁切,需要智能裁切的,请自行研究。

$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;

?>相关阅读:

javascript 文档的编码问题解决

实例说明:Linux系统终端scp命令的用法

for 语句从入门到精通

单独使用CKFinder选择图片的方法

微软反盗版验证黑屏

AJAX教程(16):通过XMLHTTP进行一次指定的HEAD请求

PHP也可以當成Shell Script

javascript实现划词标记划词搜索功能

javascript:检测FlashPlayer版本的函数

mysql5的sql文件导入到mysql4的方法

分页实现方法的性能比较

PHP开发过程中常用函数收藏

PHPCMS 验证码无法显示的解决方法

利用Oracle FGA实现审计

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值