简体   繁体   中英

Imagemagick montage 3x3 spacing 1px

I want to merge 9 images using imagemagicks convert into 3x3 tiles with a 1px spacing between the tiles. In my other, bigger version of the resulting image I have a spacing of 2px. To achieve this I've added a border of 1px to every image, and after the image has been created I'm using crop to strip the outer border.

Is there an easy way to get just 1px spacing between the tiles, unfortunately a border of 0.5px doesn't work.

The best.

Your method is similar to that used by the montage program, which has the same limitation that you found. In order to get 1px spacing between tiles, you will need a little bit more involved of a convert command. The method used here first builds the rows of the resulting image, then sticks them together, then cuts out border pixels that we don't want.

convert \( 0.png 1.png 2.png -splice 1x +append \) \
        \( 3.png 4.png 5.png -splice 1x +append \) \
        \( 6.png 7.png 8.png -splice 1x +append \) \
        -splice x1 -append -chop 1x1 \
        out.png

In more detail:

  • Each parenthesized subgroup says to add a column of width 1 to the left side of each image in the subgroup. The first image in the subgroup gets a column added, too, so we will clean this up at the end. We then append the images of our row horizontally, and then do the same for the second and third row.
  • After building our rows, we use splice to add a 1 pixel row to the top of our three rows, and append vertically.
  • At this point, we almost have the image we want, but we have a 1 pixel border on the left and on the top that we need to get rid of, so that is what that final -chop is for.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM