Generate checkerboard superposition of two images

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
ChrCoello
Posts: 3
Joined: 2017-04-12T00:23:28-07:00
Authentication code: 1151

Generate checkerboard superposition of two images

Post by ChrCoello »

I would like to find a command that allows to combine two images (A.png and B.png) and generate a checkerboard superposition of the two (like you can see below https://i.stack.imgur.com/1kYTP.png).
Image
Image A.png and B.png are 64x64. The content of these images can be completly different. The output image C.png should be composed of : top row first left tile: image A 8x8, top row second tile: image B 8x8, top row third tile image A 8x8, etc...

I have searched ImageMagick compose and convert quite a bit now without success. If anybody has any tip, that would be fantastic.

Thanks in advance, Chris.
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Generate checkerboard superposition of two images

Post by GeeMack »

ChrCoello wrote: 2017-04-12T00:29:35-07:00I would like to find a command that allows to combine two images (A.png and B.png) and generate a checkerboard superposition of the two...
It is always more helpful if you provide the version of ImageMagick you're using and let us know what platform or OS you're working on. (It's one of the rules described in THIS post at the top of the forum.) The exact commands and syntax may be very different from one version/OS/etc. to another. That said...

There are several ways to approach this. If your two input images are the same dimensions and orientation, you can create exactly the effect you describe using a command like this with IM6 from a Windows command line...

Code: Select all

convert input1.png input2.png -set option:distort:viewport "%[w]x%[h]" -filter point ^
   ( pattern:gray50 -scale 800% -virtual-pixel tile -distort SRT 0 ) -composite output.png
If you're using IM7, start the command with "magick" instead of "convert". If you're running it from a Windows BAT script you'll need to change all the single percent signs "%" to doubles "%%". If you're running it on a *nix shell or script you'll need to change the continued line caret "^" to a backslash "\" and escape the parentheses with backslashes "\( ... \)", and it may require other tweaks.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Generate checkerboard superposition of two images

Post by fmw42 »

If on Unix-like system, you can try my script, interweave, at my link below. It is based on code similar to that of GeeMack above. But his is more concise.
ChrCoello
Posts: 3
Joined: 2017-04-12T00:23:28-07:00
Authentication code: 1151

Re: Generate checkerboard superposition of two images

Post by ChrCoello »

@GeeMack yes sorry, should have said what OS (Ubuntu) and version (6.8.9-9) I am using. Thanks for your answers.
@fmw42 GREAT script, the interweave does exactly what I was looking for.

Very useful.

Christopher
Post Reply