
    h                         d dl Z d dlmZ ddlmZmZ 	 d dlmZmZ  e j                  d      Zd Z	 	 dd	Zdd
Zy# e	$ r 	 d dlZd dlZn# e	$ r	  e	d      w xY wY Bw xY w)    N)
processors   )"FILER_SUBJECT_LOCATION_IMAGE_DEBUGFILER_WHITESPACE_COLOR)Image	ImageDrawz)The Python Imaging Library was not found.z^(\d+),(\d+)$c                 $   | ryt        | t              rLt        j                  |       }|r4t	        |j                  d            t	        |j                  d            fS y	 t	        | d         t	        | d         fS y# t        t        f$ r Y yw xY w)Nr      r   F)
isinstancestrRE_SUBJECT_LOCATIONmatchintgroup	TypeError
ValueError)subject_locationms     J/home/dcms/DCMS/lib/python3.12/site-packages/filer/thumbnail_processors.pynormalize_subject_locationr      s    &,#))*:;AAGGAJQWWQZ99 	,Q/0#6Fq6I2JKK  z* s    A= =BBc                 >   t        |      }|r|st        j                  | |f|||d|S d | j                  D        \  }}d |D        \  }	}
|s|	r|
st	        |	|z  |
|z        }nt        |	|z  |
|z        }|	s||z  }	n|
s||z  }
|r2|st        ||z        }	t        ||z        }
|dt        |      z   dz  z  }|dk  s|dkD  r>|r<	 | j                  t        ||z        t        ||z        ft        j                        } d | j                  D        \  }}|t        |d	         z  |z  }|t        |d
         z  |z  }|t        ||	      z
  dz  }|t        ||
      z
  dz  }||z
  ||z
  }}||z
  ||z
  }}||dz  z
  ||dz  z
  }}||dz  z   ||dz  z   }}|d	k  r||z
  }d	}n||kD  r
|||z
  z
  }|}|d	k  r||z
  }d	}n||kD  r
|||z
  z
  }|}|s|r}t        |      t        |      t        |      t        |      f}t        r<t        j                   |       }d}|j#                  ||z
  ||z
  f||z   ||z   ffd       | j%                  |      } | S # t        $ r? | j                  t        ||z        t        ||z        ft        j                        } Y w xY w)a  
    Like ``easy_thumbnails.processors.scale_and_crop``, but will use the
    coordinates in ``subject_location`` to make sure that that part of the
    image is in the center or at least somewhere on the cropped image.
    Please note that this does *not* work correctly if the image has been
    resized by a previous processor (e.g ``autocrop``).

    ``crop`` needs to be set for this to work, but any special cropping
    parameters will be ignored.
    )zoomcropupscalec              3   2   K   | ]  }t        |        y wNfloat.0vs     r   	<genexpr>z7scale_and_crop_with_subject_location.<locals>.<genexpr>9   s     4q%(4   c              3   2   K   | ]  }t        |        y wr   r   r   s     r   r"   z7scale_and_crop_with_subject_location.<locals>.<genexpr>:   s     1q%(1r#   d   g      Y@g      ?)resamplec              3   2   K   | ]  }t        |        y wr   r   r   s     r   r"   z7scale_and_crop_with_subject_location.<locals>.<genexpr>[   s     .E!H.r#   r   r   r
   
   z#FF0000)outline)r   r   scale_and_cropsizemaxminroundr   resizer   LANCZOSAttributeError	ANTIALIASr   r   r   Drawellipser   )imr+   r   r   r   r   kwargssource_xsource_ytarget_xtarget_yscaleres_xres_ysubj_xsubj_yexeyfxfy	box_width
box_heighttexteytfxtfycrop_boxdrawesizes                                r   $scale_and_crop_with_subject_locationrM   "   s7    22BC((T D418D<BD 	D 5BGG4Hh1D1Hh88Hx'H)<=Hx'H)<= e#e#X-.HX-.H#D	/U**s{us{w	5C5 013x%7G3HI$)MM  3B /bgg.LE5 U+A.//(:FU+A.//(:F
#eX&
&!	+B
#eX&
&!	+BRZB GR"WzI Q':>)BCQ':>)BC
QwCi	uS5[!
QwCi	uS5[!	RXs3xS3s8<->>"%DELL6E>6E>:!E>6E>:<EN  PWWXIi  	5C5 013x%7G3HI$)OO  5B	5s   ;I AJJc                 d   |s| S |t         }|d}| }| j                  \  }}|\  }}	t        j                  d||	f|      } ||k  r'||	k  r"| j	                  |||z
  dz  |	|z
  dz  f       | S ||k  r| j	                  |||z
  dz  df       | S ||	k  r| j	                  |d|	|z
  dz  f       | S |} | S )Nz#fffRGBAr
   r   )r   r+   r   newpaste)
imager+   
whitespacewhitespace_colorr6   	old_imager7   r8   r9   r:   s
             r   rS   rS      s   1!IHhHhIIfx24DEE(x(2I A%8(;q'@ B 	C L 
H	IH!4 91=> L 
H	IHx$71#<=> L L    )FNFF)FN)reeasy_thumbnailsr   settingsr   r   PILr   r   ImportErrorcompiler   r   rM   rS    rV   r   <module>r^      s    	 & PG$ !bjj!12  EJHMcL}  GG GEFFG 	Gs'   < AA
AAAA