Page 1 of 1

Appending/Tiling with max width or height

Posted: 2011-07-19T07:53:30-07:00
by SineSwiper
Running into an issue with multi-file creation for image appending. Say I have either of the two queries:

Code: Select all

convert dir/*.jpg -append appended-%d.jpg
montage dir/*.jpg -tile 1x -mode Concatenate appended-%d.jpg
Both do the same thing, a vertical tile of the images, but they do it on a single image. I want to be able to append these images with a maximum height in mind. However, since these *.jpg files have a variable height, crop isn't appropriate here. Instead, I want ImageMagick to say: "If this next image would go beyond the maxHeight, then save the existing destination image, and start a new one." Montage seems like it almost has the option, but not quite:

Code: Select all

montage dir/*.jpg -tile 1x20 -mode Concatenate appended-%d.jpg
montage dir/*.jpg -tile 1x(3000px) -mode Concatenate appended-%d.jpg
The first one is a real command, but you have no idea what the number of images should be (and that could change from each multi-image destination). The second one isn't real, but it's exactly what I want. I've tried just about every geometry parameter under the sun, and they either mess with the source images (resize, add blank space, etc.), or just don't do anything. I want to declare the maximum canvas size (or at least the height), not resize it, or mess with the graphic primitives.

If this isn't possible from a single command line, can it be done with a script that uses identify %h or something along those lines? I'm tired of having to play around with letter starters all the time:

Code: Select all

convert dir/[a-c]*.jpg -append appended-1.jpg
convert dir/[d-fF]*.jpg -append appended-2.jpg
convert dir/[g-j]*.jpg dir/k[a-e]*.jpg -append appended-3.jpg
convert dir/k[f-z]*.jpg dir/[l-n]*.jpg -append appended-4.jpg
...etc...

Re: Appending/Tiling with max width or height

Posted: 2011-07-19T17:22:07-07:00
by anthony
You mean you want to only append images until you reach some maximum length (vertically in this case).
Is that what you mean?

At this time IM can not do this, montage especially is designed more for generating a array of images (even is concatenated) than columns/rows with some specified maximum limit.

However I have had on my todo list, to implement a series of 'layout' methods, that will not only replace the existing 'append' but also add limits, while providing controls for spacing and possibly even justification. However this and many other things has been put on hold for IMv7 development, now in progress.

Re: Appending/Tiling with max width or height

Posted: 2011-07-19T17:58:03-07:00
by SineSwiper
Ahh, bummer. Might be able to script it, but I'm not sure if it would fit in a perl-pie one-liner or not. The only problem would be the different potential picture #s per multi-image, so it's not like it would be a plug-in variable. It would have to be a bash while loop for each file, doing an individual append on one image. Ugh... might as well use a perl-pie to generate a script for the individual images.

Oh well, I'll work on it and post the results. Keep up the good work on this awesome tool!

Re: Appending/Tiling with max width or height

Posted: 2011-07-19T18:39:21-07:00
by anthony
Perhaps someone like Fred would like to write a script to generate appends to maximum fixed length.
It could even including things like 'minimum space between images' and 'justification spacing', as well as row/column versions.

Re: Appending/Tiling with max width or height

Posted: 2011-07-21T04:37:50-07:00
by SineSwiper
This works somewhat:

Code: Select all

identify -format "%h %f\n" 'dir/*.jpg' | perl -p -e '/^(\d+)\s+(.+)/;undef$_;$j++;$c+=$1;if ($c > 30000) {$k++;$_="convert -quality 80 dir/[X-X]* dir/$p -append -identify full$k.jpg\n";$c=$1;}$p=$2;'
You still have to figure out the right letter-based glob to make it work. I supposed I could just use $p.=" dir/$2" at the end to make it append it to a big long string.

It works as a real action command, though:

Code: Select all

identify -format "%h %f\n" 'dir/*.jpg' | perl -p -e '/^(\d+)\s+(.+)/;undef$_;$j++;$c+=$1;if ($c > 30000 || eof) {$k++;system "convert -quality 80$p -identify -append -identify full$k.jpg";print"\n\n";$c=$1;undef$p;}$p.=" dir/$2";'
Not pretty, but it's a script. Now, if IM can take that kind of code and translate it into a -maxcanvas command...

Re: Appending/Tiling with max width or height

Posted: 2011-07-21T17:24:29-07:00
by anthony
SineSwiper wrote:Now, if IM can take that kind of code and translate it into a -maxcanvas command.
As mentioned, I do plan a set of '-layout' operators that would include append, montage grids, etc.. some layout would have 'maxcanvas' limits, as well as options on padding to that canvas, and even how the extra spacing should be distributed.
However it will be something for early IMv7 beta development, and it is currently in alpha development.