Combine 3 Images on a square canvas

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
kni
Posts: 4
Joined: 2018-12-18T02:34:46-07:00
Authentication code: 1152

Combine 3 Images on a square canvas

Post by kni »

Hi,
I am novice to imagemagic, I need to add 3 different size images on a square canvas, (Image1 and Image2 in the first row and Image 3 in the second row i.e.https://www.dropbox.com/s/ylyks4agyz7x0 ... .jpg?raw=1 or https://www.dropbox.com/s/wmyq2bnyf4xo8 ... .jpg?raw=1 all the three images are expected to be centrally aligned of the canvas.

Is it possible to do this with IM? I have tried convert and also montage, in one try i was successful to combine 2 images on first row and last image in second row (as required by me) but the last image in the second row was not placed at the centre of canvas (it was on extreme left and the canvas was rectangular not square) please guide me to write the code for obtaining results as described above. Your kind help in this regard will save my several hours efforts.

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

Re: Combine 3 Images on a square canvas

Post by snibgo »

I would use append to join the images, then "-extent" to make the result square.

Code: Select all

magick in1.jpg in2.jpg -gravity center -background Blue +append in3.jpg -append +repage  -extent %[fx:max(w,h)]x%[fx:max(w,h)] out.png
Use whatever colour you want for the background, or "-background None" to make it transparent.
snibgo's IM pages: im.snibgo.com
kni
Posts: 4
Joined: 2018-12-18T02:34:46-07:00
Authentication code: 1152

Re: Combine 3 Images on a square canvas

Post by kni »

Hi Snibgo, thank you for your help, i tried this code but unfortunately it returned with this error
magick: invalid argument for option '-extent' 'max(w,h)]xmax(w,h)]' at CLI arg 11 @ error/operation.c/CLISimpleOperatorImage/2309.
is this causing due to the version of IM? im am using IM-7.0.8-16-Q16-x86-dll
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Combine 3 Images on a square canvas

Post by fmw42 »

In Unix, you likely need to enclose the -extent argument in double quotes. Does that make it work?

Try this:

Code: Select all

magick in1.jpg in2.jpg -gravity center -background Blue +append in3.jpg -append +repage  -extent "%[fx:max(w,h)]x%[fx:max(w,h)]" out.png

Please always say what platform/OS you use since syntax may vary in addition to your IM version.

If you want spacing between the images, use smush rather than append. See https://imagemagick.org/script/command- ... .php#smush

It is also a good idea to provide the input images separately, so it is easier for us to extract and test your command.





_______________________________

Please, always provide your IM version and platform when asking questions, since syntax may differ.

Also provide your exact command line and your images, if possible.

See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at http://www.imagemagick.org/discourse-se ... f=1&t=9620

If using Imagemagick 7, then see http://imagemagick.org/script/porting.php#cli


For novices, see

http://www.imagemagick.org/discourse-se ... f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
https://github.com/ImageMagick/usage-markdown
https://imagemagick.org/script/porting.php#cli
kni
Posts: 4
Joined: 2018-12-18T02:34:46-07:00
Authentication code: 1152

Re: Combine 3 Images on a square canvas

Post by kni »

Hi fmw42, thank you for a earliest possible response, I am sorry I forgot to mention my os, I am using Windows8, after getting you reply to my question I simply removed -extent argument completely an it worked as per my expectation however the output is now bigger (just double) as required by me.
What arguments i need to put in between if I wish to restrict the output to 1000x1000px (Input files are also 1000x1000px)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Combine 3 Images on a square canvas

Post by snibgo »

If you are using Windows BAT scripts, you need to double each percent sign %.
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: Combine 3 Images on a square canvas

Post by fmw42 »

What arguments i need to put in between if I wish to restrict the output to 1000x1000px (Input files are also 1000x1000px)

Code: Select all

magick in1.jpg in2.jpg -gravity center -background Blue +append in3.jpg -append +repage -resize 1000x1000 out.png
Is this what you want?
kni
Posts: 4
Joined: 2018-12-18T02:34:46-07:00
Authentication code: 1152

Re: Combine 3 Images on a square canvas

Post by kni »

Is this what you want?
Hi!
Thanks fmw24 and snibgo for the great help you are providing to me, with your shared commands i am now able to save my several hours of work.

All the commands shared by you people absolutely worked great, however at one point i am still facing issue it is when I use this syntax
+repage -resize 1000x1000
it maintained the height of the output file to 1000px but width still differ as per the combined width of all the images used in this command. here is the output what I got by using this code Image

the width of this file is 1870 and height was increased and maintained to 1000px by the system. following are the images that I've used to create this file with this command
convert +append img1.jpg img2.jpg img3.jpg +repage -resize 1000x1000 out.jpg
Image
Image
Image

the output desired by me was height = any size and width Strictly maintained to 1000px even if several images are used as input (i.e. If I include the images of mobile cover and the screen guard also.

your help in this regard will be appreciated.
Regards
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Combine 3 Images on a square canvas

Post by snibgo »

kni wrote:convert +append img1.jpg img2.jpg img3.jpg +repage -resize 1000x1000 out.jpg
That command has bad syntax. It should have operations listed in the order they are to be performed. You shouldn't "+append" before the images have been read. Perhaps you intended this:
kni wrote:convert img1.jpg img2.jpg img3.jpg +append +repage -resize 1000x1000 out.jpg
The "+append" operation results in a single image. "-resize 1000x1000" will resize (enlarge or reduce) to make the result that fits within a 1000x1000 box. If the input wasn't square, then either the width or height will be less than 1000.

I don't understand what you want instead. See http://www.imagemagick.org/script/comma ... p#geometry for possibilities.
snibgo's IM pages: im.snibgo.com
Post Reply