Alter JPG compression function to avoid bug