Selective/Variable cropping of inputs to MONTAGE

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
arber6

Selective/Variable cropping of inputs to MONTAGE

Post by arber6 »

I'm running IM 6.4.3 under XP SP3.

I'm trying to montage several images, and offset some of those images before the final output image is created.

I'm using 3 png files with transparency as my source files, and hoping to arrange all 3 images side-by-side as a png with transparency as my output file.

Input1.png = 800x3000 (no offsetting required)
Input2.png = 800x3000 (the image needs to be offset so that the bottom 100 pixels are cropped, and the new bottom aligns with the bottom of Input1.png)
Input3.png = 800x3000 (the image needs to be offset so that the bottom 200 pixels are cropped, and the new bottom aligns with the bottom of Input1.png)

The outputfile, Output.png, should have a height of 400, and be 1 row of input images.

I tried the montage approach, but, initially, the only way I can get it to work was to crop Input2.png by explicity providing the y-value (3000-100=2900). Ideally I could do this just by offsetting the page, like with other commands?

For example, this seems to work, but what if I don't know the image height (in order to calculate the crop size)?

Code: Select all

montage input1.png input2.png[x2900+0+0] input3.png[x2800+0+0] -background none -tile x1 -geometry x400+1+1 output.png
This worked a little better (I don't have to calculate the crop size anymore, but I still need to know the image height)

Code: Select all

montage input1.png input2.png[x3000+0-100] input3.png[x3000+0-200] -background none -tile x1 -geometry x400+1+1 output.png
But when I substitute the 3000 for %h, it doesn't appear to offset anymore?!?

Code: Select all

montage input1.png input2.png[x%h+0-100] input3.png[x%h+0-200] -background none -tile x1 -geometry x400+1+1 output.png
I also found that offsetting the other direction causes problems...

Code: Select all

montage input1.png input2.png[x3000+0+100] input3.png[x3000+0+200] -background none -tile x1 -geometry x400+1+1 output.png
This seemed to have the effect of cropping images to heights of 2900 and 2800 respectively, when I explicitly requested 3000. So the cropped image was shorter but with the same width - so the aspect ratio changes, and the contents of the crop subsequently scale (in the geometry argument) to be larger, relative to the other images in the final montage.

I'd rather not have to calculate the crop height, or even know the image height. Furthermore, I'm working with large images, so it might be more efficient to read the files with just a #x# read modifier, to keep them small as they're loaded in. (sidenote: It's a shame you can't resize AND crop using a read modifier.)

Maybe the viewport flag could be used in the read modifier (it doesn't seem to be supported now), and then it would be possible to viewport the image/canvas.

The only other apprach I can think of is using a delegate.

Or am I missing something?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Selective/Variable cropping of inputs to MONTAGE

Post by fmw42 »

I am not sure I understand completely.

But, I don't believe that you can use this syntax, [x2800+0+0]. I think you must use [widthxheight+xoffset+yoffset]. You will need to compute the width beforehand as a variable and then use the variable as [${width}x2800+0+0].

The other way to do this is to use convert with a sequence of composites to resize and place each image where you want to put it.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Selective/Variable cropping of inputs to MONTAGE

Post by snibgo »

In Windows 7, but it should work in XP:

Code: Select all

convert %infile% -format "set ww=%%w\nset hh=%%h" info:%TEMP%\getsize.bat

call %TEMP%\getsize.bat
Then you can use %ww% and %hh% for width and height.
snibgo's IM pages: im.snibgo.com
Post Reply