Update compat.py

optimizing condition of image format