Montage can't swap

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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Montage can't swap

Post by snibgo »

Why can't montage use the "swap" option?

I want to extend a 360-degree panorama by glueing a crop from the right to left, and another crop from the left to the right. To avoid re-reading the input file, I want to use clone, something like:

Code: Select all

montage ^
  input.png ^
  ( +clone -gravity East -crop 10x100+0+0%%! +repage ) ^
  ( +clone -crop 10x100+0+0%%! +repage ) ^
  -swap 0,1 -tile x1 -geometry +0+0 out.png
Montage objects to the "swap", but I can't see a logical reason for this.

(6.5.8-8 Q16 on Windows 7.)
snibgo's IM pages: im.snibgo.com
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Montage can't swap

Post by magick »

ImageMagick support two types of command line parser depending on the utility. Convert uses the post-fix parser and montage uses the pre-fix parser. The swap option is only supported by the post-fix parser.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Montage can't swap

Post by snibgo »

Ah, thanks. Is the pre-fix/post-fix distiction documented somewhere? Are there plans to "regularise" the parsers across the utilities?

I realise my code above would need work even if "swap" worked with Montage. This code does what I want::

Code: Select all

montage ^
  ( input.png -gravity East -crop 10x100+0+0%%! +repage ) ^
  input.png ^
  ( input.png -gravity West -crop 10x100+0+0%%! +repage ) ^
  -tile x1 -geometry +0+0 out.png
but this eats memory, as input.png is 22878 x 3293 pixels. I could use Q8 instead, to halve the memory use. And I could generate the crops from separate commands. Any other solutions for this problem?
snibgo's IM pages: im.snibgo.com
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Montage can't swap

Post by magick »

We choose a parser for each command-line utility depending on what we're trying to accomplish. For montage we need to act on an image as it appears on the command-line (pre-fix parser) whereas with convert we delay action on the image filename until the command line is consumed (post-fix parser) or if a close parenthesis is encountered.

Concerning memory. ImageMagick Q8 consumes about 1/2 as much memory as Q16, however, you can also use resource limits. For example, add -limit area 4GB to your command line to force large images to cache to disk rather than memory. The command runs slower but it stops it from consuming your memory and possibly slowing down system performance. You can even set limits in the policy.xml file if you want to set a global memory limit, for example.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Montage can't swap

Post by snibgo »

Thanks for the explanation.

I want to avoid caching to disk, as that kills performance of IM and my computer in general. input.png is 75 M pixels. At 8 bytes per pixel, replicated 3 times, it needs 1.8 GB, which sometimes gives me the disk-caching dead-computer syndrome. I suspect I'll go the multiple command route (one convert to create the two small crops, then one montage to glue the left-crop, input and right-crop together).

Thanks again.
snibgo's IM pages: im.snibgo.com
Post Reply