join many equal sized images into one?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
newuser_71

join many equal sized images into one?

Post by newuser_71 »

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

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;

##
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: join many equal sized images into one?

Post by fmw42 »

newuser_71

Re: join many equal sized images into one?

Post by newuser_71 »

thanks so much for your help! Montage looks like what i need, i've looked at that link but im not sure how to integrate those commands into the code i posted earlier - for example how could i join together 4 images (two wide by two deep) and then output this to the web browser as a .png?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: join many equal sized images into one?

Post by fmw42 »

try

montage rose: rose: rose: rose: -background blue -geometry +10+10 -tile 2x2 rose_montage.png

Is that what you want? Note rose: (with colon) is an internal IM image. See http://www.imagemagick.org/script/forma ... tin-images

the -geometry provides the spacing between images, the -tile sets the arrangement
newuser_71

Re: join many equal sized images into one?

Post by newuser_71 »

fmw42 wrote:try

montage rose: rose: rose: rose: -background blue -geometry +10+10 -tile 2x2 rose_montage.png

Is that what you want? Note rose: (with colon) is an internal IM image. See http://www.imagemagick.org/script/forma ... tin-images

the -geometry provides the spacing between images, the -tile sets the arrangement
I'm having some trouble fitting those commands within the script i posted originally, as i'd like to read in the images i want to montage from a folder on a web server but then create one large montaged image just output to the web browser.

I tried replacing the line from my first example..
$status = $image->Append(stack=>0);

with...

$status = $image->Montage();

..and i'm getting closer to what i want - i get my first 2 tiles along the top and the next two underneath (so its a 2x2). Although the image size is reduced (i want to keep the original) and also there is a gap of a few pixels between images. I think i need to incorporate -geometry +0+0 but not sure where? do the parameters go inside the () after Montage or is the method i'm using to read in the URL's pointing to the images not the right way to go?

Thanks!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: join many equal sized images into one?

Post by fmw42 »

sorry, I only know command line scripting and not any API
Post Reply