Fix JPEG images not being saved optimally

Thanks HowardLo!