Hey Guys,
I am new to ImageMagick and I am trying to take an image which is a grid of tiles and insert a 2 pixel transparent space between each tile.
Input example:
Output example:
(Extra space around the border would be fine.)
I've manage to separate all the tiles and add a border with:
convert floorTiles.png -crop 128x128 ^
-set filename:tile "%%[fx:page.x/128+1]_%%[fx:page.y/128+1]" ^
+repage +adjoin -border 1x1 "tile_%%[filename:tile].png"
This yields extra images that aren't full size tiles, how do I get rid of them?
How can I use the column_row file name to re-combine the image with every image in the correct location?
How do make the border transparent?
Or perhaps there is an easier way of doing this?
Thanks,
Poohshoes
Add padding to tile sheet. [Resolved]
Add padding to tile sheet. [Resolved]
Last edited by poohshoes on 2013-11-17T23:22:58-07:00, edited 1 time in total.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Add padding to tile sheet.
Your input isn't a multiple of 128 pixels because it has a white border on two edges. You can trim this off:
So if you want the individual files:
Or if you want one row with all 10 tiles:
Note that I have added a 1-pixel white border around each tile, so they are separated by 2 pixels, and each is 130x130. At the end I remove the outer white border.
If we want 7 on the first row, 7*130 = 910. We crop the long line at 910 and append these vertically.
Code: Select all
-bordercolor White -border 1 -trim +repage
Code: Select all
convert ^
floorTiles.png ^
-bordercolor White -border 1 -trim +repage ^
-crop 128x128 ^
-set filename:tile "%%[fx:page.x/128+1]_%%[fx:page.y/128+1]" ^
+repage +adjoin -border 1x1 "tile_%%[filename:tile].png"
Code: Select all
convert ^
floorTiles.png ^
-bordercolor White -border 1 -trim +repage ^
-crop 128x128 ^
-border 1 ^
+append ^
-trim +repage ^
tOneRow.png
If we want 7 on the first row, 7*130 = 910. We crop the long line at 910 and append these vertically.
Code: Select all
convert ^
floorTiles.png ^
-bordercolor White -border 1 -trim +repage ^
-crop 128x128 ^
-border 1 ^
+append ^
-crop 910x130 ^
-append ^
-trim +repage ^
tTwoRows.png
snibgo's IM pages: im.snibgo.com
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Add padding to tile sheet.
Sorry, you also asked about transparency. In each command the second added border, around the individual tiles, is white because that was the set "-bordercolor". Instead we can make it transparent:
Code: Select all
-bordercolor None -border 1
snibgo's IM pages: im.snibgo.com
Re: Add padding to tile sheet.
Thanks so much snibgo. I settled on the following script which, unlike my example, requires the input to have a transparent background.
Cheers,
poohshoes
Code: Select all
convert ^
floorTiles.png ^
-bordercolor None -border 1 -trim +repage ^
-crop 128x128 +repage ^
-border 1 ^
+append ^
-crop 780x130 +repage ^
-append ^
-trim +repage ^
output.png
poohshoes
Re: Add padding to tile sheet.
I also stumbled upon this http://www.imagemagick.org/Usage/transf ... cing_tiles which may be an easier way of doing it.