3

I'm trying to create a table of thumbnails for example 100 thumbnails 10x10 with GD Library. I saw that imagemagick has a montage function that would probably be useful but I'm wondering if GD library can do this as well.

I thought I could maybe do it by just outputting all of the images in a simple html table and converting that table to an image, but it appears that might not be possible. Any help or suggestions?

maplater
  • 171
  • 2
  • 12

2 Answers2

3

This is most certainly possible. You can resize images, as well as copy images into another image with GD. To find out more about resizing, check out this resize function I made: http://www.spotlesswebdesign.com/blog.php?id=1

But let's say your images are already resized to 10x10, and you had an array filled with 100 urls leading to different 10x10 gifs.

$montage_image = imagecreatetruecolor(100, 100);
$x_index = 0;
$y_index = 0;
foreach($array_with_100_10x10_gif_urls as $gif_image_url) {
    $current_image = imagecreategif($gif_image_url);
    imagecopy($montage_image, $current_image, $x_index * 10, $y_index * 10, 0, 0, 10, 10);
    imagedestroy($current_image);
    $x_index++;
    if ($x_index > 9) {
        $x_index = 0;
        $y_index++;
    }
}
// place code for saving the montage image as a file or outputting to teh browser here.
imagedestroy($montage_image);
dqhendricks
  • 19,030
  • 11
  • 50
  • 83
  • if you want to use images of a different type, simply switch out the gif specific functions with functions for your image type. you will have to incorporate some sort of switch if you want to have the ability to use multiple image types. – dqhendricks Jan 06 '11 at 22:56
  • to output the file read this documentation: http://www.php.net/manual/en/function.imagegif.php – dqhendricks Jan 06 '11 at 22:59
  • This is great, seriously this right now is the only real example of this on the internet. Thanks. – maplater Jan 08 '11 at 13:12
1

GD cant do that. Why not just use imagemagick?

EDIT: GD can do that, but you'd have to do it manually, there is no GD function comparable to imagemagick's montage.

profitphp
  • 8,104
  • 2
  • 28
  • 21
  • Er... why can't you do this via GD? You'd have to write the code of course, but compositing multiple images into a single montage is well within GD's capabilities. – John Parker Jan 06 '11 at 21:51
  • Well sure, but i think he was asking if there was a comparable function.. which there isn't. Guess i should have been more clear. – profitphp Jan 06 '11 at 21:54
  • if anyone would care to post an example of said iMagick function being used to replace the GD code above, I would be very grateful. I see the command line example in the docs, but I havent been able to find an equivalent PHP example. – Dmitri May 24 '12 at 17:02