ó
TR¹Nc           @   s9   d  Z  d d l m Z d e f d „  ƒ  YZ d „  Z d S(   sM   
Utility functions for handling images.

Requires PIL, as you might imagine.
iÿÿÿÿ(   t   Filet	   ImageFilec           B   sA   e  Z d  Z d „  Z e e ƒ Z d „  Z e e ƒ Z d „  Z RS(   s€   
    A mixin for use alongside django.core.files.base.File, which provides
    additional features for dealing with images.
    c         C   s   |  j  ƒ  d S(   Ni    (   t   _get_image_dimensions(   t   self(    (    sE   /home/panlixing/Python_Projects/gaeseries/django/core/files/images.pyt
   _get_width   s    c         C   s   |  j  ƒ  d S(   Ni   (   R   (   R   (    (    sE   /home/panlixing/Python_Projects/gaeseries/django/core/files/images.pyt   _get_height   s    c         C   sN   t  |  d ƒ sG |  j } |  j ƒ  t |  ƒ |  _ | rG |  j ƒ  qG n  |  j S(   Nt   _dimensions_cache(   t   hasattrt   closedt   opent   get_image_dimensionsR   t   close(   R   R   (    (    sE   /home/panlixing/Python_Projects/gaeseries/django/core/files/images.pyR      s    	
(	   t   __name__t
   __module__t   __doc__R   t   propertyt   widthR   t   heightR   (    (    (    sE   /home/panlixing/Python_Projects/gaeseries/django/core/files/images.pyR   	   s   		c         C   sÕ   y d d l  m } Wn t k
 r3 d d l } n X| j ƒ  } t } t |  d ƒ r^ |  } n t |  d ƒ } t } zG x< | j d ƒ } | s’ Pn  | j	 | ƒ | j
 ry | j
 j Sqy d SWd | rÐ | j ƒ  n  Xd S(   sF   Returns the (width, height) of an image, given an open file or a path.iÿÿÿÿ(   R   Nt   readt   rbi   (   t   PILR   t   ImportErrort   Parsert   FalseR   R	   t   TrueR   t   feedt   imaget   sizet   NoneR   (   t   file_or_patht   PILImageFilet   pR   t   filet   data(    (    sE   /home/panlixing/Python_Projects/gaeseries/django/core/files/images.pyR
      s*    		N(   R   t   django.core.filesR    R   R
   (    (    (    sE   /home/panlixing/Python_Projects/gaeseries/django/core/files/images.pyt   <module>   s   