Page 1 of 1

Add padding to tile sheet. [Resolved]

Posted: 2013-11-14T04:14:21-07:00
by poohshoes
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:
Image

Output example:
Image
(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

Re: Add padding to tile sheet.

Posted: 2013-11-14T09:09:22-07:00
by snibgo
Your input isn't a multiple of 128 pixels because it has a white border on two edges. You can trim this off:

Code: Select all

-bordercolor White -border 1 -trim +repage
So if you want the individual files:

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"
Or if you want one row with all 10 tiles:

Code: Select all

convert ^
  floorTiles.png ^
  -bordercolor White -border 1 -trim +repage ^
  -crop 128x128 ^
  -border 1 ^
  +append ^
  -trim +repage ^
  tOneRow.png
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

convert ^
  floorTiles.png ^
  -bordercolor White -border 1 -trim +repage ^
  -crop 128x128 ^
  -border 1 ^
  +append ^
  -crop 910x130 ^
  -append ^
  -trim +repage ^
  tTwoRows.png

Re: Add padding to tile sheet.

Posted: 2013-11-14T09:15:34-07:00
by snibgo
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

Re: Add padding to tile sheet.

Posted: 2013-11-14T18:23:41-07:00
by poohshoes
Thanks so much snibgo. I settled on the following script which, unlike my example, requires the input to have a transparent background.

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
Cheers,
poohshoes

Re: Add padding to tile sheet.

Posted: 2013-11-15T18:47:41-07:00
by poohshoes
I also stumbled upon this http://www.imagemagick.org/Usage/transf ... cing_tiles which may be an easier way of doing it.