³ò
Je|Mc           @   s‹   d  Z  d d k Z d d k Z d d k Z d d k Z d d d g Z d „  Z d d „ Z d d „ Z	 d	 „  Z
 e d
 j o e
 ƒ  n d S(   s#   Multimedia helpers for images, etc.iÿÿÿÿNt   choose_heightt   get_dimensions_pilt   get_dimensionsc         C   s$   t  | ƒ t  | ƒ } t |  | ƒ S(   s   Return the height corresponding to ``new_width`` that's proportional
       to the original size (``width`` x ``height``).
    (   t   floatt   int(   t	   new_widtht   widtht   heightt
   proportion(    (    s`   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/media.pyR    
   s    c         C   s@   d d k  } y | i |  ƒ } Wn t j
 o | Sn X| i S(   s)  Get an image's size using the Python Imaging Library (PIL).

    ``path`` is the path of the image file.

    ``default`` is returned if the size could not be ascertained. This
    usually means the file does not exist or is not in a format recognized by
    PIL.

    The normal return value is a tuple: ``(width, height)``.

    Depends on the `Python Imaging Library
    <http://pypi.python.org/pypi/PIL>`_. If your application is not
    otherwise using PIL, see the ``get_dimensions()`` function, which does
    not have external dependencies.
    iÿÿÿÿN(   t   Imaget   opent	   Exceptiont   size(   t   patht   defaultR	   t   im(    (    s`   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/media.pyR      s    	c         C   s®  t  i i |  ƒ } y t |  d ƒ } Wn t j
 o | Sn Xz]| i d ƒ } | i d ƒ o÷ d } } | i d ƒ xÏ t	 oÇ d } | i | ƒ } y t
 i d | ƒ \ }	 }
 } Wn t j
 o Pn X|	 d j o Pn d t |
 ƒ j o
 d	 j n o1 d
 } | i | ƒ } t
 i d | ƒ \ } } q{ | i | d ƒ q{ W| | f Sn@| i d ƒ p | i d ƒ ob | i d ƒ | i d ƒ } | d j o5 | i d ƒ } t
 i d | ƒ \ } } | | f Sq—n¾ | i d ƒ p | i d ƒ oK | i d ƒ | i d ƒ } t
 i d | ƒ \ } } } } } | | f SnS | i d ƒ oB | i d ƒ | i d ƒ } t
 i d | ƒ \ } } | | f Sn | SWd | i ƒ  Xd S(   sÿ  Get an image's size using only the Python standard library.

    ``path`` is the path of the image file.

    ``default`` is returned if the size could not be ascertained. This
    usually means the file does not exist or is not in a recognized format.
    PIL. Only JPG, PNG, GIF, and BMP are supported at this time.

    The normal return value is a tuple: ``(width, height)``.

    The algorithms are based on a `PyCode recipe
    <http://www.pycode.com/modules/?id=32&tab=download>`_ by
    Perenzo/Welch/Ray.

    This helper recognizes fewer image formats and is potentially less
    accurate than ``get_dimensions_pil()``.

    Running this module as a script tests this helper. It will print the
    size of each image file specified on the command line.
    t   rbi   s   ÿØi   i   s   !ccHs   ÿiÀ   iÃ   i   s   !xHHs   ‰PNG

s   ŠMNG

i   t   IHDRt   MHDRi   s   !IIt   GIF87at   GIF89ai   i   s   <HHBBBt   BMi   s   <IIN(   R   R   (   t   osR   t   abspathR
   t   IOErrort   readt
   startswitht   Nonet   seekt   Truet   structt   unpackR   t   ordt   close(   R   R   t   apatht   ft   headerR   R   t   lengtht   buft   markert   codet   controlt   flagst   bcit   par(    (    s`   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/media.pyR   (   s\    	
 $ !c          C   så   t  i d }  |  p t  i d ƒ n x¹ |  D]± } t i i | ƒ } d | Gt i i | ƒ p d GHq, n t | ƒ \ } } | d  j o | d  j o	 d GHq, | d  j o
 d } n | d  j o
 d } n d | | f GHq, Wd  S(   Ni   s3   usage: %s FILES ...
Prints dimensions of each images   %s:s%   does not exist or is not a plain files   could not get dimensionst   UNKNOWNs   %s x %s(	   t   syst   argvt   exitR   R   R   t   isfileR   R   (   t   filest   fileR"   R   R   (    (    s`   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/media.pyt   test_get_dimensionsr   s$     	

t   __main__(   NN(   NN(   t   __doc__t   loggingR   R   R.   t   __all__R    R   R   R   R4   t   __name__(    (    (    s`   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/WebHelpers-1.2-py2.5.egg/webhelpers/media.pys   <module>   s   	J	 