o 3a @s>dZddlZddlZddlmZGdddeZd ddZdS) zO Utility functions for handling images. Requires Pillow as you might imagine. N)Filec@s0eZdZdZeddZeddZddZdS) ImageFilez A mixin for use alongside django.core.files.base.File, which provides additional features for dealing with images. cC |dS)Nr_get_image_dimensionsselfr :/usr/lib/python3/dist-packages/django/core/files/images.pywidth zImageFile.widthcCr)Nrrr r r heightr zImageFile.heightcCs,t|ds|j}|t||d|_|jS)N_dimensions_cache)close)hasattrclosedopenget_image_dimensionsr)rrr r r rs zImageFile._get_image_dimensionsN)__name__ __module__ __qualname____doc__propertyr rrr r r r r s   rFc Cs4ddlm}|}t|dr|}|}|dnt|d}d}zjd} ||}|s.nOz||Wn.t j yR}z|j d drGnWYd }~nd }~wt j y[Yn tycYnw|jrx|jjW|rr|S||S|d 9}q&W|r|d S||d S|r|w||w) z Return the (width, height) of an image, given an open file or a path. Set 'close' to True to close the file at the end if it is initially in an open state. r)rreadrbTir zError -5N)NN)PILrParserrtellseekrrfeedzliberrorargs startswithstruct RuntimeErrorimagesizer) file_or_pathrPillowImageFilepfilefile_pos chunk_sizedataer r r r!sR            r)F)rr&r"django.core.filesrrrr r r r s