title: Optimal spritesheet algorithm
body: <p>One thing I've noticed about spritesheets is that their filesize is not entirely consistent. When you have individual images, assuming they are compressed properly, their filesize won't change. But with spritesheets, the filesize of the image can vary a lot depending on how the images are arranged.</p>
  
  <p>As an example, I created this spritesheet:<br>
  <a href="http://pokebattlers.net/img/misc/forumstars.png" rel="nofollow noreferrer">Sheet http://pokebattlers.net/img/misc/forumstars.png</a> I tried horizontal, I tried 2x3 in portrait and landscape, I tried all <code>6! = 720</code> possible arrangements for the images, and what I found was that the order of the stars made absolutely no difference (I didn't really expect it to, given the image is indexed and so all that changed was the palette being rearranged), but the vertical layout produced a smaller file than any other.</p>
  
  <p>Is there any algorithm that can help determine the optimal arrangement of images in a spritesheet, or is it just a case of brute-force "try everything and find the smallest one"?</p>
  
  <p>Also, why is it that a vertical lineup produces a smaller file than a horizontal one in this and the few other cases I've tried?</p>