what's the best way to combine multiple pics into one big pics

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
niyanwen
Posts: 81
Joined: 2019-05-23T16:19:12-07:00
Authentication code: 1152

what's the best way to combine multiple pics into one big pics

Post by niyanwen »

Hey, I need to generate one big by combine around 20 small pics
each small pics I have its location(offset x, y) and I have the big image size

what is the best command to do with it?
if I used in java, is there any example to take a look?

User avatar
fmw42
Posts: 26061
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: what's the best way to combine multiple pics into one big pics

Post by fmw42 »

What you probably want is to flatten all the images onto the background. You can do that in one command line using -flatten. See https://imagemagick.org/Usage/layers/#flatten. Sorry, I do not know the Java ImageMagick API nor do I know of any Java examples. See https://github.com/techblue/jmagick or search on Google or StackOverflow.

niyanwen
Posts: 81
Joined: 2019-05-23T16:19:12-07:00
Authentication code: 1152

Re: what's the best way to combine multiple pics into one big pics

Post by niyanwen »

Hi,

I follow this command, but the issue I face is the background of image is white or something else, do you know how to setup background as transparent, and only keep the images I want to combine

niyanwen
Posts: 81
Joined: 2019-05-23T16:19:12-07:00
Authentication code: 1152

Re: what's the best way to combine multiple pics into one big pics

Post by niyanwen »

the command generated is : convert -size 1990x3535 xc:transparent -page +0+0 image1.png -page +497+0 image2.png -layers flatten image3.png

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

Re: what's the best way to combine multiple pics into one big pics

Post by snibgo »

Insert "-background None" before "-layers flatten".
snibgo's IM pages: im.snibgo.com

niyanwen
Posts: 81
Joined: 2019-05-23T16:19:12-07:00
Authentication code: 1152

Re: what's the best way to combine multiple pics into one big pics

Post by niyanwen »

works! thank you! do you know why I need to have this "xc:transparent" in the cmd, looks like without this, it won't work

User avatar
fmw42
Posts: 26061
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: what's the best way to combine multiple pics into one big pics

Post by fmw42 »

It sets the limits/size of your output. You can remove it, but if your images are smaller, then you would get a smaller output. If your images are larger, then they will be clipped to those bounds.

niyanwen
Posts: 81
Joined: 2019-05-23T16:19:12-07:00
Authentication code: 1152

Re: what's the best way to combine multiple pics into one big pics

Post by niyanwen »

got it, thank you!

User avatar
fmw42
Posts: 26061
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: what's the best way to combine multiple pics into one big pics

Post by fmw42 »

You could remove the xc:transparent and use -layers mosaic. It will expand the canvas to so that all your images show. See https://imagemagick.org/Usage/layers/#layers

niyanwen
Posts: 81
Joined: 2019-05-23T16:19:12-07:00
Authentication code: 1152

Re: what's the best way to combine multiple pics into one big pics

Post by niyanwen »

but my use case for now is I need to set a default image size for the whole image, so I need to keep xc:transparent right?

User avatar
fmw42
Posts: 26061
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: what's the best way to combine multiple pics into one big pics

Post by fmw42 »

Yes, I believe that would be so, if you need a particular size. I was just trying to reply to your question and explain your options.

Post Reply