
    
3jH                     D    S SK r S SKrS SKJr   " S S5      rS\0rSS0rg)    N)Imagec                   >    \ rS rSrSr\S 5       rSrSrSr	Sr
S rS	rg
)ConstrainImage   z_
A node that constrains an image to a maximum and minimum size while maintaining aspect ratio.
c           	      L    SSSSSS.4SSSS.4SSSS.4SSSS.4SS/S	S04S
.0$ )NrequiredIMAGEINTi   r   )defaultminyesnor   )images	max_width
max_height	min_width
min_heightcrop_if_required )clss    V/home/wildlama/comfy/ComfyUI/custom_nodes/ComfyUI-Custom-Scripts/py/constrain_image.pyINPUT_TYPESConstrainImage.INPUT_TYPES
   s^     $#a%@A$$q&AB#1%=>$!A&>?&+T]Y4E$F	
 		
    r	   constrain_imageimage)Tc                 *   US:H  n/ nU GH  nSUR                  5       R                  5       -  n	[        R                  " [        R
                  " U	SS5      R                  [        R                  5      5      R                  S5      n
U
R                  u  pX-  n[        [        X5      U5      n[        [        X5      U5      nX-  U:  a/  [        [        X-  5      U5      nU(       a  [        XU-  -  5      nO.[        [        X-  5      U5      nU(       a  [        XU-  -  5      nU
R                  X4[        R                  5      nU(       a]  X:  d  X:  aS  [        X-
  S-  S5      n[        X-
  S-  S5      n[        X5      U-   n[        X5      U-   nUR                  UUUU45      n[        R                   " U5      R                  [        R"                  5      S-  n[$        R&                  " U5      S   nUR)                  U5        GM     U4$ )Nr   g     o@r      RGB   )N)cpunumpyr   	fromarraynpclipastypeuint8convertsizer   maxintresizeLANCZOScroparrayfloat32torch
from_numpyappend)selfr   r   r   r   r   r   resultsr   iimgcurrent_widthcurrent_heightaspect_ratioconstrained_widthconstrained_heightresized_imagelefttoprightbottoms                        r   r   ConstrainImage.constrain_image   s   +u4Euyy{((**A//"''!Q"4";";BHH"EFNNuUC,/HH)M(9L #C$A9 M!$S%Dj!Q 5D$',>,M(NPY$Z!#),^O`?`-a)b&%(->-M)NPZ%["#(+MN`=`,a(b%JJ(9'NPUP]P]^M%6%BFXFe-9a?C-:q@!D-9D@/<sB - 2 2D#uf3M NHH]3::2::FNM!,,];EBMNN=)= @ zr   r   N)__name__
__module____qualname____firstlineno____doc__classmethodr   RETURN_TYPESFUNCTIONCATEGORYOUTPUT_IS_LISTr   __static_attributes__r   r   r   r   r      s6     

 

 L HHN#r   r   zConstrainImage|pysssssu   Constrain Image 🐍)r2   r#   r%   PILr   r   NODE_CLASS_MAPPINGSNODE_DISPLAY_NAME_MAPPINGSr   r   r   <module>rR      s8      : :z n 
 4 r   