Use sharp for image resizing instead of image magic.  It's 100x faster on my machine.

Also adjusted gallery so that images scaled for justification don't look bad if they are scaled a lot.