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: 71
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 » 2019-05-23T16:21:58-07:00

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: 25668
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 » 2019-05-23T16:33:45-07:00

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: 71
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 » 2019-05-28T11:41:43-07:00

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: 71
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 » 2019-05-28T11:46:53-07:00

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: 12320
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 » 2019-05-28T11:57:43-07:00

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

niyanwen
Posts: 71
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 » 2019-05-28T12:38:41-07:00

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: 25668
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 » 2019-05-28T12:40:55-07:00

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: 71
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 » 2019-05-28T12:45:20-07:00

got it, thank you!

User avatar
fmw42
Posts: 25668
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 » 2019-05-28T12:52:14-07:00

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: 71
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 » 2019-05-28T19:14:02-07:00

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: 25668
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 » 2019-05-28T19:52:54-07:00

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