缺點:長寬不一的圖片會被拉伸變形,不能智能裁切,需要智能裁切的,請自行研究。
$config = array();
$config['path'] = "./";
$config['t_width'] = 120;
$config['t_width'] = 120;
$config['t_width'] = 120; ['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($file,$ $im_width, $im_height, $type) = getimagesize($file);
if($type != IMAGE_JPG) {
continue
} href='{$file}'>$file" . ENDL;
$im = @imagecreatefromjpeg($file);
if(!$im) {
$op .= " fail -> couldn't create sour image pointer." . ENDL;
continue;
}
if(file_exists($config)['prefix'])
if(file_exists($config['prefix')) , strlen($config['prefix'])) == $config['prefix']) {
$op .= "note -> this file has already got) .umbnailEND. ;
}
$to = imagecreatetruecolor($config['t_width'],$config['t_height']);
if(!$to) {
$op =. > couldn't create dest image pointer." . ENDL;
continue;
}
if(!imagecopyresampled($to,0$im,
if(!imagecopyresampled($to,0$im, 00,0$ ], $config['t_height'], $im_width, $im_height)) {
$op .= "fail -> couldn't create thumbnail. }
//儲存檔案
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 "";
exit;
?>
以上就介紹了產生縮圖 PHP批次產生縮圖的程式碼,包括了產生縮圖方面的內容,希望對PHP教學有興趣的朋友有所幫助。