montaging lots of files

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
tg_in_sd

montaging lots of files

Post by tg_in_sd »

As an IM newbie, I'm a bit frustrated because it is SO powerful, and I know you must be able to do what I want, but just can't figure it out...any help would be appreciated.

I have a large number of files (90) that I want to montage together via a PHP script. They have to be processed in a specific order, so globb'ing is out. The host provider won't install MagickWand for PHP, so I can only use the basic command line tools.

I know that my command line is going to look something like
montage <input list> -tile x1 -geometry 0x0+0+0 -background none <outputfile.gif>

But since an external list of files isn't supported, and I don't want to worry about hitting the shell line limit, it semms I need to do something like

Loop through files in order a..z
append next image to montage

So it looks like my command line is going to be
montage myMontage.gif next_file.gif -tile x1 -geometry 0x0+0+0 -background none myMontage.gif

Think that will work? Is there a better way to do what I need?

Thanks!

Terry
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: montaging lots of files

Post by Bonzo »

There are probably a couple of ways you can do it, I have not worked a lot with glob but I would assume you could sort the results before using the code ?

Anyway here is one way I did it by reading the directory. http://www.rubblewebs.co.uk/imagemagick ... p_list.jpg

You could create an array and use that:

Code: Select all

<?php
$read = 'imagemagick/original_images/';

$dirArray = array('boots.png', 'bathhat.jpg', 'albir.jpg', 'flowers.jpg');

sort( $dirArray );

$indexCount = count($dirArray);

for ($i=0; $i<$indexCount; $i++)
{
$name .= $read.$dirArray[$i].' ';
}

exec("convert -background black $name +append php_list.jpg");
?> 
This is why I like working with php as you can use all the php functions to modify, sort build arrays etc. :D
tg_in_sd

Re: montaging lots of files

Post by tg_in_sd »

Thanks for the reply Bonzo. I may try your approach and if it fails I will fall back to the "append" solution.

T.

PS. In case anyone else ever needs to do the same thing, I think the montage command I'll be using is actually

Code: Select all

montage  <inputlist>  -mode Concatenate -tile x1 -background none  outputfile.gif
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: montaging lots of files

Post by Bonzo »

You can use the array in your method as well:

Code: Select all

<?php
exec("montage $name -mode Concatenate -tile x1 -background none php_list1.png");
?>
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: montaging lots of files

Post by fmw42 »

If you rename all the images so they start with some common name such as "image", i.e. image_restofname.gif
you can then try:

montage image*.gif ....

or

montage image* ...


You may also be able to do the following:


montage `cat list.txt` ...

where list.txt is a text file containing the file names (and paths, if necessary to each file), one per row.
tg_in_sd

Re: montaging lots of files

Post by tg_in_sd »

If I montage just a few images, it works fine but I get an error return of "8" when I run the full-blown command, and it is surprisingly difficult to find what the error code means!

argh!

But this loop finally did the trick. MANY THANKS for all the suggestions. ;-)

Code: Select all

while($row = mysql_fetch_object($result)) {
    $mycmd = "montage -mode Concatenate montage.gif " . $row->graphic . " montage.gif";
    exec ($mycmd); 
}
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: montaging lots of files

Post by anthony »

If your shell command line is getting too ling then you can use a trick involving the MIFF: file format.

When MIFF: is used for multiple images, the image data is just concatanated together one after another. That means you can create a pipeline of images feeding into montage without needing to list all the images..

If I have a list image files in a file "image_file_list.txt" to be montaged you can do this..

Code: Select all

cat image_file_list.txt | while read file; do
  convert "$file" miff:-
done | montage miff:-   ...options... output.gif
A trickier alternative is

Code: Select all

  cat image_file_list.txt | xargs -i# convert "#" miff:-  |\
       montage miff:-   ...options... output.gif
At no point is the actual image filename placed all at once on the command line, but is read from a file.

When combined with PHP you could replace the "cat image_file_list.txt | " part with a PHP feed so that PHP itself feeds the filename (one line at a time) to the script.

For more information on MIFF and another example of this technique (generating a color table of unknown size) see IM Examples, File handling, MIFF http://imagemagick.org/Usage/#miff
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply