
    
3j                     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	)
ConstrainImageforVideo   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    `/home/wildlama/comfy/ComfyUI/custom_nodes/ComfyUI-Custom-Scripts/py/constrain_image_for_video.pyINPUT_TYPES"ConstrainImageforVideo.INPUT_TYPES
   s^     $#a%@A$$q&AB#1%=>$!A&>?&+T]Y4E$F	
 		
    r	   constrain_image_for_videoimagec                 t   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        [$        R*                  " USS9nGM     WUR                  S5      4$ )	Nr   g     o@r      RGB   )N)dim)cpunumpyr   	fromarraynpclipastypeuint8convertsizemaxr   intresizeLANCZOScroparrayfloat32torch
from_numpyappendcat)selfr   r   r   r   r   r   resultsr   iimgcurrent_widthcurrent_heightaspect_ratioconstrained_widthconstrained_heightresized_imagelefttoprightbottom
all_imagess                         r   r   0ConstrainImageforVideo.constrain_image_for_video   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=)72J? B JOOA.00r   r   N)__name__
__module____qualname____firstlineno____doc__classmethodr   RETURN_TYPESRETURN_NAMESFUNCTIONCATEGORYr   __static_attributes__r   r   r   r   r      s6     

 

 LL*HH$1r   r   zConstrainImageforVideo|pysssssu   Constrain Image for Video 🐍)r3   r$   r&   PILr   r   NODE_CLASS_MAPPINGSNODE_DISPLAY_NAME_MAPPINGSr   r   r   <module>rU      s9      ;1 ;1| %&< 
 %&F r   