Page 1 of 1

How to eliminate whitespace in a montage, then adjoin?

Posted: 2016-06-01T08:08:11-07:00
by whatshisname
Greetings,

Running ImageMagick 6.9.4-3 Q16 armv7l 2016-05-21

Calling imagemagick using system call in PHP 7.0.7

Running Arch Linux armv7 version on Odroid C-1

On my website, I'm creating montages from user-submitted images of various aspect ratios. I'm only accepting 2 images at this point.
Imagemagick beautifully creates the montage. I'm going for common height to begin with, then a maximum width.

If I receive 2 images that have the exact same aspect ratio, the montage is perfect!

The problem I have not been able to figure out, after several hours of digging deep into the man pages, is how to remove the white space between a montage created from 2 images with dissimilar aspect ratios. When that happens I end up with something like the ascii graphic below.

Code: Select all

---------------------------------------
|    x     |            |      x      !
|    x     |            |      x      !
|    x     |            |      x      !
|    x     |   Delete   |      x      !
|    x     |            |      x      !
|    x     |            |      x      !
|    x     |            |      x      !
---------------------------------------

The x'ed columns are the pictures I want to keep. The "Delete" column is the white space I would like to delete.

It feels like I need to use the "gravity" option but I just can't figure out how to pull it off.

Fred's "adjoin" script is close except I only have one picture to deal with and not 2.

I could probably get there if I could split the image down the middle, crop then adjoin but I can't depend on the middle being the best place to slice each time.

Fred's "splitcrop" in reverse would do the trick!

I've tried and failed. I now humbly submit my problem to the imagemagick wizards.

Thank you in advance.

~krb

Re: How to eliminate whitespace in a montage, then adjoin?

Posted: 2016-06-01T10:13:16-07:00
by fmw42
Add -geometry +0+0 in montage. Or just use +append. For the latter see http://www.imagemagick.org/Usage/layers/#append

Re: How to eliminate whitespace in a montage, then adjoin?

Posted: 2016-06-01T14:20:32-07:00
by whatshisname
Thanks, @fmw42. Your "-geometry +0+0" option did indeed get rid of the white space, but at the expense of the common height I wanted for the photos.

But your pointing out of the "append" parameter started me re-thinking my approach completely.

I now have what I was looking for by first converting each image to the maximum height allowed, appending them together and finally re-sizing that image to the maximum width allowed.

The pictures are turning out perfectly now, in fewer steps to boot! :-)

Thanks for setting me on the right track.

Re: How to eliminate whitespace in a montage, then adjoin?

Posted: 2016-06-01T14:33:41-07:00
by fmw42
Glad you figured that out. Hope you are doing it in one command line.

Re: How to eliminate whitespace in a montage, then adjoin?

Posted: 2016-06-01T15:40:21-07:00
by whatshisname
Not quite one command.

First, I'm testing each image to see if I have a jpg or not. If not, I'm converting the image to a jpeg, resizing to maximum height along the way.

Then appending the 2 images together.

For security, reasons, I'm doing each of these operations outside of the document root.

Then I do the final re-sizing to maximum width while placing it inside the document root for display by the webserver.

If there's a way of doing all of this in one command, I'm all ears!

Re: How to eliminate whitespace in a montage, then adjoin?

Posted: 2016-06-01T16:56:39-07:00
by fmw42
It is a bad idea to convert to jpg for intermediate images. Each time you read and write JPG you lose quality. I would suggest if you have to have intermediates, then use png or tif with lossless compression.

If you post your set of commands, we can see how much we can combine. Also post you input images and output image, so we can test with your data. You can upload to some free hosting service such as dropbox.com and put the URLs here. Do not upload appended images. Keep them separate and individual.

Example:

Image ... Image

Code: Select all

convert zelda3.jpg monet3.jpg -resize x256 +append zelda_monet.jpg
Image