色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

PHP批量生成縮略圖的代碼

缺點:長寬不一的圖片會被拉伸變形,不能智能裁切,需要智能裁切的,請自行研究。
<?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; 
?>

php技術PHP批量生成縮略圖的代碼,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 新乡市| 天门市| 鄂伦春自治旗| 阳高县| 十堰市| 稻城县| 十堰市| 秦皇岛市| 章丘市| 洛浦县| 临清市| 桐梓县| 上高县| 朝阳市| 蚌埠市| 韶关市| 剑川县| 册亨县| 江华| 曲阜市| 贵港市| 华蓥市| 府谷县| 蒙山县| 诸城市| 新沂市| 乌鲁木齐市| 华宁县| 石台县| 青川县| 恭城| 武陟县| 新和县| 兴隆县| 龙山县| 佛坪县| 兰州市| 青海省| 五峰| 长寿区| 确山县|