Skip to content

Instantly share code, notes, and snippets.

@ldd
Last active February 28, 2016 20:47
Show Gist options
  • Select an option

  • Save ldd/7d370240f7a5f8efbe63 to your computer and use it in GitHub Desktop.

Select an option

Save ldd/7d370240f7a5f8efbe63 to your computer and use it in GitHub Desktop.

preparations

  • install imagemagick
  • download and unzip assets

step-by-step guide

STEP 1: Finding the dimensions of the image

identify npc5.png

In this, case we get that the image is 312x288

STEP 2: Finding information about the assets

We visually count the number of rows and cols of characters.

In this case, it is 12 columns and 8 rows.

We visually calculate the dimensions of each character.

In this case, it is 16x32

STEP 3: Calculating what to crop

We divide our dimensions by the rows and cols, which gives us:

312/12 = 26 pixels for the sprite's width

288/8 = 36 pixels for the sprite's height

Thus, we have a padding of 10 pixels to remove in the width of each character, and 4 pixels to remove in the height of each character.

STEP 4:Getting the tiles

we run:

convert npc5.png  -crop 12x8@ +repage -gravity South -crop 16x36+0-4\! +repage parts-%d.png

or using a much more readable format, we run:

convert npc5.png  -crop 12x8@ +repage -shave 5x0 -chop 0x4 parts-%d.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment