Added image optimization

...but it's awfully slow. I'll probably remove this and just deal with the extra 10-20k per image.