自动批量生成缩略图

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

是生成缩略图的

把文件放目录下

如果目录下有图片会自动生成小图片

适合批量生成小图,做图片站的能用的着吧.

<?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 -> <a href='{$file}'>$file</a>" . 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: <a href='{$config['prefix']}{$file}'>{$config['prefix']}{$file}</a>" . ENDL;

$done++;

}

}

}

closedir($handle);

$op .= "fin -> {$done} file(s) written" . ENDL;

echo "<pre>";

echo $op;

echo "</pre>";

exit;

?>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航