Ńň
ŹKáHc @ 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( ( s4 /usr/lib/python2.6/site-packages/webhelpers/media.pyR
s c C s: d d k } y | | } Wn t j
o | SX| i S( sĄ Get an image's size using the Python Imaging Library (PIL)
Returns ``(width, height)`` as two integers, or ``default`` if the size
could not be ascertained. Failuer usually means the file does not exist
or is not in a format recognized by PIL.
Depends on the Python Imaging Library (http://pypi.python.org/pypi/PIL).
See ``get_dimensions()`` if your application is not otherwise using PIL.
i˙˙˙˙N( t Imaget Exceptiont size( t patht defaultR t im( ( s4 /usr/lib/python2.6/site-packages/webhelpers/media.pyR s
c C s t i i | } y t | d } Wn t j
o | SXzQ| 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 | \ } } qx | i | d qx W| | f S| i d p | i d
o_ | i d | i d } | d j o2 | i d } t
i d | \ } } | | f Sn¸ | i d p | i d oH | i d | i d } t
i d | \ } } } }
} | | f S| i d o? | i d | i d } t
i d | \ } } | | f S| SWd | i Xd S( s( Get an image's size using only the Python standard library
Returns ``(width, height)`` as two integers, or ``default`` if the size
could not be ascertained. Failure usually means the file does not exist
or is not in a recognized format. Only JPG/PNG/GIF/BMP are supported at
this time.
The algorithms are based on a PyCode recipe by Perenzo/Welch/Ray.
(http://www.pycode.com/modules/?id=32&tab=download)
This helper recognizes fewer image formats and is potentially less
accurate than ``get_dimensions_pil()``.
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