2013-03-18 73 views
0

嘿,我有一個任務,我需要做一個畫廊。這段代碼現在只顯示圖片,但我想爲這些圖片製作縮略圖。如何製作縮略圖?

我該怎麼做?有什麼建議麼?

<html> 
<head> 
<style type="text/css"> 

ul { 
    list-style:none; 
} 

</style> 

</head> 
<body> 
<ul> 
<?php 
    $imgdir = 'images/'; 
    $allowed_types = array('png', 'jpg', 'jpeg', 'gif'); 
    $dimg = opendir($imgdir); 
    while($imgfile = readdir($dimg)) { 
     if(in_array(strtolower(substr($imgfile, -3)), $allowed_types) or in_array(strtolower(substr($imgfile, -4)), $allowed_types)) { 
      $a_img[] = $imgfile; 
     } 
    } 
    echo "<ul>"; 

    $totimg = count($a_img); 
    for($x=0; $x < $totimg; $x++) { 
     echo "<li><img src='" . $imgdir . $a_img[$x] . "' /></li>"; 
    } 
    echo "</ul>"; 

?> 
</ul> 
</body> 
</html> 
+0

使用GD庫 – Stasel 2013-03-18 09:37:58

+0

'我想使縮略圖這些pictures'嗯,我想我也不會反對。你已經得到了我的祝福。如果你碰巧有一個確切的_question_,那不是寫你的代碼的請求,隨意在這裏發佈它。並請閱讀[常見問題] – ppeterka 2013-03-18 09:41:05

+0

http://stackoverflow.com/questions/5254325/using-the-php-gd-library-to-resize-and-save-images-is-hell這是已有的答案所以。 – 2013-03-18 09:42:34

回答

0

嘗試Imagine庫。它是強大的圖像處理庫。

+0

我有不同的感覺,這應該是一個評論,而不是一個答案。 – ppeterka 2013-03-18 09:41:25

0

可以使用Imagick擴展。

事情是這樣的:

<?php 

header('Content-type: image/jpeg'); 

$image = new Imagick('tc5.jpg'); 

// If 0 is provided as a width or height parameter, 
// aspect ratio is maintained 
$image->thumbnailImage(100, 0); 

echo $image; 

?> 

http://php.net/manual/en/imagick.cropthumbnailimage.php