Montage and the crop the output in one command?

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
mhulse
Posts: 61
Joined: 2016-03-17T18:46:22-07:00
Authentication code: 1151

Montage and the crop the output in one command?

Post by mhulse »

Hello,

I have a set of tiles that I am using montage to create an equirectangular image using IM/montage/bash.

The resulting image output of the montage command needs to be cropped.

I've tried variations of:

Code: Select all

montage \
  +frame \
  +shadow \
  -quality 100 \
  -tile 5x3 \
  -geometry 512x512+0+0 \
  -crop 2508x1254+0+0 \
  "$currentDir/tile_*.jpg" \
  "$currentDir.jpg"
What would be the most optimal way to crop the resulting montaged image?

Basically, I'm just wanting to avoid creating multiple JPGs ... Could I use bash's pipe (I tried this but I was not sure how to get montage into convert using pipe).

Any tips/help would be great.
Homebrew-installed ImageMagick 7.0.8-27 Q16 x86_64 2019-02-12 | macOS Mojave | MacBook Pro
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Montage and the crop the output in one command?

Post by fmw42 »

Pipe your montage output to a new magick command that will crop the result and make a new output.

Something like

Code: Select all

montage \
+frame \
+shadow \
-quality 100 \
-tile 5x3 \
-geometry 512x512+0+0 \
"$currentDir/tile_*.jpg" \
miff:- | magick - "$currentDir.jpg"
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Montage and the crop the output in one command?

Post by snibgo »

As Fred says, and the "convert" can do whatever cropping or other processing is required. However as IM v7 is used, I suggest "magick montage" and "magick" instead of "montage" and "convert".
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Montage and the crop the output in one command?

Post by fmw42 »

Thanks, snibgo. Too used to using convert. I have corrected my post.
mhulse
Posts: 61
Joined: 2016-03-17T18:46:22-07:00
Authentication code: 1151

Re: Montage and the crop the output in one command?

Post by mhulse »

Thanks Fred and snibgo!!!! I greatly appreciate the assistance!

It's been about a year since I last used IM on the regular... I didn't realize there was a new command name! That's cool! I need to read up on the changes since I last used IM.

Thanks again!!!!
Homebrew-installed ImageMagick 7.0.8-27 Q16 x86_64 2019-02-12 | macOS Mojave | MacBook Pro
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Montage and the crop the output in one command?

Post by fmw42 »

see https://imagemagick.org/script/porting.php#cli

Note for other tools such as montage, mogrify, identify, you do need to preface those with magick. Just not convert.
mhulse
Posts: 61
Joined: 2016-03-17T18:46:22-07:00
Authentication code: 1151

Re: Montage and the crop the output in one command?

Post by mhulse »

fmw42 wrote: 2019-02-18T11:29:36-07:00 see https://imagemagick.org/script/porting.php#cli

Note for other tools such as montage, mogrify, identify, you do need to preface those with magick. Just not convert.
Thank you so much for the help! I love ImageMagick. Not only is the tool itself amazing, but people like you and snibgo make it so much more approachable to users like me. :)

With that said, I'll post back my exact command once I get it finalized, just in case seeing my particular use case will help others in the future.

Have an excellent day!
Homebrew-installed ImageMagick 7.0.8-27 Q16 x86_64 2019-02-12 | macOS Mojave | MacBook Pro
mhulse
Posts: 61
Joined: 2016-03-17T18:46:22-07:00
Authentication code: 1151

Re: Montage and the crop the output in one command?

Post by mhulse »

Thanks again for the help snibgo and Fred, it's much appreciated.

Here's what I'm using to combine and crop:

Code: Select all

magick \
  montage \
  +frame \
  +shadow \
  -tile 5x3 \
  -geometry 512x512+0+0 \
  "$currentDir/tile_*.jpg" \
  +depth \
  miff:- \
  | \
  magick \
  - \
  -quality 100 \
  -crop 2508x1254+0+0 \
  "$currentDir.jpg"
I ended up moving the quality to the right side of the pipe ... Based on docs, it sounds like miff: and +depth already use the highest res possible.

ImageMagick rocks!
Homebrew-installed ImageMagick 7.0.8-27 Q16 x86_64 2019-02-12 | macOS Mojave | MacBook Pro
Post Reply