Often I find myself needing to take many PNG images and join them into a larger image.

Specifically, in this particular case, I'd like to take 2 PNGs of roughly equal width (±2px) and different heights and create a new PNG where the first is above the other. E.g.

enter image description here

The join should be seamless.

Is there a command line tool/app that does this? Best would be if Preview offers a solution.

  • sips is the closest thing I know of, but I don't think this'll do what you want. Anything wrong with using a photo editing program like GIMP? – JMY1000 Apr 26 '17 at 20:26
  • @JMY1000 I'm hoping there's a native method or some simple one-liner terminal script. Using GIMP to do this simple task takes forever (starting up GIMP, creating new image of correct dimensions, pasting in the two PNGs.) Maybe there's a specialist app that isn't native to macOS, I wouldn't mind installing it if there was. – theonlygusti Apr 26 '17 at 20:28
  • Fair enough. Not aware of anything off the top of my head. – JMY1000 Apr 26 '17 at 20:34
  • 1
    In your OP you said, "Best would be if Preview offers a solution.", Preview doesn't have that functionality and neither does sips as mention in the comments. In your comment you said, "I'm hoping there's a native method or some simple one-liner terminal script", there is no native method that I know of, but that does't mean there isn't. The third-party app ImageMagic has a montage command to create a composite image by combining several separate images. You might have to first rotate the images using some other command of ImageMagic, or sips. Can't say for sure as I've not used it. – user3439894 Apr 26 '17 at 21:40
  • @user3439894 I already have ImageMagick installed, I'll look into the montage command. :) – theonlygusti Apr 26 '17 at 22:07

ImageMagick can do this:

convert 1.png 2.png -append result.png

Alignment options can be (optionally) specified using the -gravity switch,

  • -gravity East align the right edges
  • -gravity West align the left edges
  • -gravity center align the centers

Note: using +append instead of -append will stitch the images together horizontally, i.e. side-by-side rather than one above the other.

| improve this answer | |
  • 1
    +1 for coming back to share that ImageMagick could do this and how you did it. :) – Monomeeth Apr 27 '17 at 9:06
  • 1
    Is there anyway to link some gui type interaction here? I find most of the time I want to convert screenshots with long names that are hard to distinguish between effectively at the command line. It would be nice if I could pick the images I want combined via finder, and then the rest of this script runs. – Rey Jul 17 '19 at 21:22
  • @Rey type convert and then drag and drop the files from finder into terminal – theonlygusti Jul 18 '19 at 10:04
  • @Rey — I added an answer to address your question: apple.stackexchange.com/a/395488/136164 – Mat Gessel Jul 5 at 21:18

If you want to do this entirely in Finder, you can create an Automator service and run it as a Service through the right-click menu.

  1. open Automator.app
  2. New > Service
  3. Service receives selected "Image Files" in "Finder.app"
  4. add Utilities > Run Shell Script
  5. enter the script shown below (include the trailing newline)
  6. Save as "Image Append - Vertical" (saves to ~/Library/Services/Image Append - Vertical.workflow)

To run — select two or more images in Finder, right-click > Services > Image Append - Vertical

A new file will be created with the name of the first image suffixed with "v" before the file extension.

Bash Script:

DIR=$(dirname -- "$1")
FILE=$(basename -- "$1")
# call ImageMagick with selected files and create new file with "v" suffix
convert "$@" -append "${DIR}/${NAME}v.${EXT}"
# GraphicsMagick version (smaller & faster than ImageMagick)
#/opt/local/bin/gm convert "$@" -append "${DIR}/${NAME}v.${EXT}"

Automator screenshot (macOS High Sierra):

Automator.app screenshot

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .