title: Pillow: splitting a spritesheet into seprate images
body: <p>I have a <a href="https://play.pokemonshowdown.com/sprites/smicons-sheet.png" rel="nofollow noreferrer">spritesheet</a> with sprites of 40x30 each, and I'm trying to split it up into indivdual sprites named from <code>0-number_of_sprites</code></p>
  
  <pre><code>from PIL import Image
  from os import mkdir
  
  mkdir("assets/icons")
  sheet = Image.open("assets/icons.png")
  count = 0
  
  for x in range(12):
      for y in range(97):
          a = (x + 1) * 40
          b = (y + 1) * 30
          icon = sheet.crop((a - 40, b - 30, a, b))  # Problem here
          icon.save("assets/icons/{}.png".format(count))
          count += 1
  </code></pre>
  
  <p>And the problem is where I marked as such. The coordinates of <code>a, b</code> are the top left and top right of each sprite, going from <code>40, 30</code> to <code>480, 2910</code></p>
  
  <p>EDIT: Put in where the problem was, accidently deleted it before. My problem is this code gets each indivdual sprite, but seems to do it in a completly random order, for instance #384 on the list, was saved as #32 for some reason, and #10 as #1</p>