Skip to content
Snippets Groups Projects
jpeg_format.py 279 B
Newer Older
  • Learn to ignore specific revisions
  • Jesper Zedlitz's avatar
    Jesper Zedlitz committed
    from PIL import Image, UnidentifiedImageError
    
    
    def is_valid(resource, file):
        """Check if the content is a readable JPEG image."""
    
        try:
            with Image.open(file.name, formats=["JPEG"]):
                return True
        except UnidentifiedImageError:
            return False