简体   繁体   中英

Combining ImageMagick import/montage commands into one-liner

Long story short from the command line I need to take a screenshot, crop two areas of that screenshot and join them back together side-by-side.

The separate stages which work fine look like this:

$> import -window root -crop '1280x400+0+0' left.png

$> import -window root -crop '1280x400+0+400' right.png

$> montage -geometry 1280x400 left.png right.png out.png

However, I'm not sure how to combine this into one command.

OS is Linux (Raspbian) if that helps.

I'm not sure how to do any cropping as part of a magick import so I'll import and forward to a regular magick command for processing.

To mimic your approach, that would be:

magick import -window root png:- | magick png:- \
  \( -clone 0 -crop 1280x400+0+0   \) \
  \( -clone 0 -crop 1280x400+0+400 \) \
  -delete 0 +append result.png

That first grabs the screen with import and pipes it on as a PNG to a second command that clones the image and crops the left half, clones it again and crops the right half, deletes the original and places the two crops side-by-side.


There is an easier way that works for you though. If you crop without an offset, all the cropped areas will remain in your stack:

magick import -window root png:- | magick png: -crop x50% +append result.png

Note : I am also using 50% of the height as the crop to save me having to do any maths

Note : If you want a magenta gap between the two halves, add -background magenta near the start and replace +append with +smush 10 to place them 10 pixels apart.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM