backporting image optimizations

See: https://github.com/GigaOM/gigaom/issues/5525