0

Hey I have an assignment where I need to make a gallery. This code I have now just shows the pictures but I want to make thumbnails for these pictures.

How can I do this? Any suggestions?

<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>
IlhamiD
  • 143
  • 1
  • 2
  • 8
  • `I want to make thumbnails for these pictures` Umm, I think I won't object to it. You've got my blessing to do it. If you happen to have an exact _question_, that is not a request to write your code, feel free to post it here. And please read the [FAQ] – ppeterka Mar 18 '13 at 09:41
  • http://stackoverflow.com/questions/5254325/using-the-php-gd-library-to-resize-and-save-images-is-hell Here is the already existing answer on SO. – metalfight - user868766 Mar 18 '13 at 09:42
  • http://webcheatsheet.com/php/create_thumbnail_images.php – Vikas Gautam Mar 18 '13 at 09:47

3 Answers3

0

Try Imagine library. It is powerful image processing library.

Ziumin
  • 4,800
  • 1
  • 27
  • 34
0

This Question/Answer will help you, and give you idea how to re-size an image.

Image Re-sizing in PHP

Community
  • 1
  • 1
Muhammad Ummar
  • 3,541
  • 6
  • 40
  • 71
0

You can use the Imagick extension.

Something like this:

<?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

daniel__
  • 11,633
  • 15
  • 64
  • 91