PHP批量生成缩略图的代码_PHP教程

WBOY
Freigeben: 2016-07-21 15:51:16
Original
915 Leute haben es durchsucht

缺点:长宽不一的图片会被拉伸变形,不能智能裁切,需要智能裁切的,请自行研究。
$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 "

";  <br>echo $op;  <br>echo "
Nach dem Login kopieren
"; 
exit; 
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/319200.htmlTechArticle缺点:长宽不一的图片会被拉伸变形,不能智能裁切,需要智能裁切的,请自行研究。 ?php $config=array(); $config['path']="./"; $config['t_width']=120...
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!