imagemagickoffsettile

imageMagick: hexagonal tiling of many different images (having the same size)


I have many different PNG images all with the same size (142x163). These are badges for students. You can see three examples below, but there are more of them. I would like to create a single large image where all individual badges are arranged in a hexagonal grid to maximize the printed area. I just need to leave a little space between them to cut them out safely.

I'm wondering what the best way is to go about this.

I have a list of how many badges of each kind I need to print, and I can write code to specify the position (offset) of each individual badge in the hexagonal grid. However, I'm not sure about the correct way to feed this information into a script for ImageMagick to execute.

I guess I need something like: create an image placing badge1.png at position 1, badge2.png at position 2, badge3.png at position 3, badge3.png at position 4, and so on. This could go on for a bit, with 50 to 100 badges (I'm thinking of filling an A3 sheet with 3cm x 3cm badges).

What would the correct syntax be? Would ImageMagick handle this?

Thanks a lot for any insight.

Francesco

[![badge1][1]][1]
[![badge2][2]][2]
[![badge3][3]][3]

badge1 badge2 badge3

EDIT: as required, I'm attaching the script I'm currently using:

magick -background none \
\( ph4campoBstatico.png ph5EqMaxOndeEM.png MMprodVett.png ph4UeV_elettrici.png +smush 8 +repage -set page +0+0 \) \
\( MMsimboli.png ph3dinamicaSNI.png ph1prefissi.png ph1calibroVentesimale.png +smush 8 +repage -set page +76+130 \) \
-layers merge +repage \
-background white -flatten \
result.png

This command works, but it converts an entire "row" to grayscale whenever the first image is grayscale (see output below).

Since the number of files involved is much larger than 8, I tried to write this command in a file "script" and run it as magick -script script. What I find is that I have to prepend -write to the filename. Also, it seems to me that the backslashes at the end of each line are unimportant in the file.

The output of the command is

result.png

Only the first image in the second row should be black and white. The others should be in color. Colors are "removed" from a row only when the first image is grayscale.


Solution

  • Try adding -colorspace sRGB or -type truecolor after reading the images in Imagemagick. Also prepend PNG24: to the output filename if the previous does not work by itself but only for PNG output.

    magick -background none \
    \( ph4campoBstatico.png ph5EqMaxOndeEM.png MMprodVett.png ph4UeV_elettrici.png -colorspace sRGB +smush 8 +repage -set page +0+0 \) \
    \( MMsimboli.png ph3dinamicaSNI.png ph1prefissi.png ph1calibroVentesimale.png -colorspace sRGB +smush 8 +repage -set page +76+130 \) \
    -layers merge +repage \
    -background white -flatten \
    PNG24:result.png