Page 1 of 1

montaging lots of files

Posted: 2008-02-08T13:13:19-07:00
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

Re: montaging lots of files

Posted: 2008-02-08T14:00:39-07:00
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

Re: montaging lots of files

Posted: 2008-02-08T14:51:11-07:00
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

Re: montaging lots of files

Posted: 2008-02-08T15:02:33-07:00
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");
?>

Re: montaging lots of files

Posted: 2008-02-08T18:47:28-07:00
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.

Re: montaging lots of files

Posted: 2008-02-08T23:23:27-07:00
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); 
}

Re: montaging lots of files

Posted: 2008-02-10T19:23:28-07:00
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