Modified stream to encode image to buffer