B
    KDb              	   @   s   d dl Z d dlZd dlmZ d dlmZ dZdd Zdd Zd	d
 Z	dd Z
dd Zdd Zdd Zdd dd ee	eeeee
g	Zdd Zdd Zdd Zdd ZdS )    N)Image)settingsi  c             C   s   |  tjS )N)	transposer   ZFLIP_LEFT_RIGHT)im r   1G:\easytimepro\master/mysite/tools\image_utils.pyflip_horizontal   s    r   c             C   s   |  tjS )N)r   r   ZFLIP_TOP_BOTTOM)r   r   r   r   flip_vertical   s    r	   c             C   s   |  tjS )N)r   r   Z
ROTATE_180)r   r   r   r   
rotate_180   s    r
   c             C   s   |  tjS )N)r   r   Z	ROTATE_90)r   r   r   r   	rotate_90   s    r   c             C   s   |  tjS )N)r   r   Z
ROTATE_270)r   r   r   r   
rotate_270    s    r   c             C   s   t t| S )N)r   r   )r   r   r   r   r   $   s    r   c             C   s   t t| S )N)r   r	   )r   r   r   r   
transverse(   s    r   c             C   s   | S )Nr   )xr   r   r   <lambda>,       r   c             C   s   | S )Nr   )r   r   r   r   r   -   r   c             C   s   yLt | drJ|  }|dk	rJ|t }tjr:td|t| t| }|| S W n6 tk
r`   Y n$ t	k
r   ddl
}|  Y nX | S )aW  
    Extract the oritentation EXIF tag from the image, which should be a PIL Image instance,
    and if there is an orientation tag that would rotate the image, apply that rotation to
    the Image instance given to do an in-place rotation.

    :param Image im: Image instance to inspect
    :return: A possibly transposed image instance
    _getexifNz2[DEBUG][image_utils.apply_orientation.orientation]r   )hasattrr   ORIENTATION_EXIF_TAGr   DEBUGprinttypeORIENTATION_FUNCS	TypeError	Exception	traceback	print_exc)r   eZorientationfr   r   r   r   apply_orientation8   s    	
r   c             C   s0   t | }|dd}t|}|| dS )z* Adjust the orientation of the JPEG image RGBARGBN)r   openconvertr   save)srcdstr   r   r   r   adjust_orientationR   s    
r&   c             C   s~   t | }|dd}|j\}}|| |kr4dS x(|| |kr\t|d }t|d }q6W |||ft j}|| dS )zScale down to the specified pixel value and the scale are keeping (Size is a unit of pixel)
    @:param size: type is int ,eg:320 * 240
    r   r    Ng?)r   r!   r"   sizeintresize	ANTIALIASr#   )r$   r%   r'   r   r   youtr   r   r   resize_by_pixelZ   s    

r-   c             C   s   |d9 }t | }tj| }d}xF||krh|dkrh||jt j}|j||d tj|}|d8 }q$W |dkr| |krt	
| | dS )zlProcess images according to the specified file size(Size is a unit of KB)
    @:param size: type is int
    i   d   r   )Zquality   N)r   r!   ospathgetsizer)   r'   r*   r#   shutilcopy)r$   r%   r'   r   Zsize_tmpqr,   r   r   r   resize_by_sizej   s    
r6   )r0   r3   ZPILr   Zdjango.confr   r   r   r	   r
   r   r   r   r   r   r   r&   r-   r6   r   r   r   r   <module>   s0   