首頁  >  文章  >  後端開發  >  產生縮圖 PHP批次產生縮圖的程式碼

產生縮圖 PHP批次產生縮圖的程式碼

WBOY
WBOY原創
2016-07-29 08:38:23866瀏覽

缺點:長寬不一的圖片會被拉伸變形,不能智能裁切,需要智能裁切的,請自行研究。
$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教學有興趣的朋友有所幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn