Optimized thumbnail-generation algorithm (edge-maximizing crop & resize)