Fixes possible crash with empty image data.