Achieving this layout 2x2 but then with a layer on top in the middle

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
henry_neves7
Posts: 4
Joined: 2017-04-05T08:25:47-07:00
Authentication code: 1151

Achieving this layout 2x2 but then with a layer on top in the middle

Post by henry_neves7 »

Hi there

I'm very new to ImageMagick so please excuse my ignorance.

I'm trying to achieve this layout: https://www.dropbox.com/s/3p7ir297q2exq ... 2.png?dl=0

What I've got so far is this:

Code: Select all

convert \( image-1.png  image-2.png -bordercolor white -border 20  +append \) \
             \( image-3.png  image-4.png -bordercolor white -border 20  +append \) \
             \( image-5.png  +append \) \
             -bordercolor white -border 5 -gravity south -background white -append  result.jpg
What I'm struggling with is the concept of getting the last appended image to position centrally, on top of the other images.

Any help would be great, thanks very much

Henry
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Achieving this layout 2x2 but then with a layer on top in the middle

Post by snibgo »

Your code "+appends" 1 and 2, so they are side-by-side in one image. Then 3 and 4 likewise, in a second image.
middle wrote:\( image-5.png +append \)
That would put 5 next to anything else in that list. But there is nothing else, so "+append" does nothing. Now we have a third image.

Then you "-append" all three images vertically.

It would seem better to append just the first two images vertically. Then composite 5 over the result.

Like this (untested code):

Code: Select all

convert \
\( image-1.png image-2.png -bordercolor white -border 20 +append \) \ 
\( image-3.png image-4.png -bordercolor white -border 20 +append \) \ 
-bordercolor white -border 5 \
-append \
image-5.png  
-gravity Center -compose Over -composite \
-background white result.jpg
snibgo's IM pages: im.snibgo.com
henry_neves7
Posts: 4
Joined: 2017-04-05T08:25:47-07:00
Authentication code: 1151

Re: Achieving this layout 2x2 but then with a layer on top in the middle

Post by henry_neves7 »

Thank you so much!

This was the final code that got the desired output:

Code: Select all

convert \( image-1.png  image-2.png -bordercolor white -border 20  +append \) \
             \( image-3.png  image-4.png -bordercolor white -border 20  +append \) \
             \-append \
             \image-5.png \
             -gravity center -compose over -composite \
             -background white result.jpg
Henry
henry_neves7
Posts: 4
Joined: 2017-04-05T08:25:47-07:00
Authentication code: 1151

Re: Achieving this layout 2x2 but then with a layer on top in the middle

Post by henry_neves7 »

Also, if I wanted to add a tiled image as a background to this, would I need to do a montage and then compose the rest over the top?

I've tried using -tile x1 but it's saying it can't open the file.

Thanks
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Achieving this layout 2x2 but then with a layer on top in the middle

Post by snibgo »

First, use "-bordercolor none". This adds a border, but transparent.

Once you have made one image from the five images, you can composite that over your backgound image, like this:

Code: Select all

convert \
\( image-1.png image-2.png -bordercolor none -border 20 +append \) \
\( image-3.png image-4.png -bordercolor none -border 20 +append \) \
-append \
image-5.png \
-gravity center -compose over -composite \
background.png \
+swap \
-composite \
-background white result.jpg
I've used your version of the code, but removed the superfluous "\" from the start of "\image-5.png" and "\-append". They may be harmless, but seem confusing.

EDIT: I fouled up the first version.
snibgo's IM pages: im.snibgo.com
henry_neves7
Posts: 4
Joined: 2017-04-05T08:25:47-07:00
Authentication code: 1151

Re: Achieving this layout 2x2 but then with a layer on top in the middle

Post by henry_neves7 »

Great!! That and making the border colour transparent has achieved the exact thing I wanted.

Thanks so much for your help :)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Achieving this layout 2x2 but then with a layer on top in the middle

Post by snibgo »

Oops, yes, I fouled up my own copy-paste. Sorry about that. As you say, the bordercolor needs to be "None".
snibgo's IM pages: im.snibgo.com
Post Reply