join many equal sized images into one?
Posted: 2010-05-23T13:04:18-07:00
Hello,
I'm new to imagemagick, and am trying to join together several small images into a single large image, reading the small images from a folder and outputting the combined image to the browser.
I've looked at using 'Append' and can successfully join together a series of images either horizontally (all in a row), OR vertically (stacked below the previous one) using the 'stack' option. But I want join in both directions at the same time (for example join 2 tiles wide by 2 tiles deep.. 2x2, 10x10, 100x100 tile image...). All my small tiles are exactly the same square size in pixels... so i want to join a 'grid' of smaller tiles into one big image.
Below is the code i've used to join images together in one direction but i'd really appreciate some advice as to how i can develop this to join a grid of smaller images as explained above. I'm not even sure if Append is the best technique for this!?
I'm new to imagemagick, and am trying to join together several small images into a single large image, reading the small images from a folder and outputting the combined image to the browser.
I've looked at using 'Append' and can successfully join together a series of images either horizontally (all in a row), OR vertically (stacked below the previous one) using the 'stack' option. But I want join in both directions at the same time (for example join 2 tiles wide by 2 tiles deep.. 2x2, 10x10, 100x100 tile image...). All my small tiles are exactly the same square size in pixels... so i want to join a 'grid' of smaller tiles into one big image.
Below is the code i've used to join images together in one direction but i'd really appreciate some advice as to how i can develop this to join a grid of smaller images as explained above. I'm not even sure if Append is the best technique for this!?
Code: Select all
#!C:/Perl/bin/perl.exe -w
#
use Image::Magick;
# Turn off buffer
$| = 1;
# Build URL request string
my $url = "http://localhost/tiles/tile1.png" ;
my $url2 = "http://localhost/tiles/tile2.png" ;
my $url3 = "http://localhost/tiles/tile3.png" ;
my $url4 = "http://localhost/tiles/tile4.png" ;
my $image = new Image::Magick;
my $status = $image->Read($url,$url2,$url3,$url4);
die "$status\n" if $status;
# stack=>0 is horizontal =>1 is vertical
$status = $image->Append(stack=>0);
print "Content-type: image/png\n\n";
binmode STDOUT;
$status->Write('png:-');
undef $image;
##