4

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
5

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.

  • 1
    +1 for coming back to share that ImageMagick could do this and how you did it. :) – Monomeeth Apr 27 '17 at 9:06
  • 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 at 21:22
  • @Rey type convert and then drag and drop the files from finder into terminal – theonlygusti 2 days ago

You must log in to answer this question.

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