o
    Y+iN                     @   s   d Z zddlZddlZdd Zde_W nA eyT   zddlmZ ddlZdd Zde_W n$ eyQ   zdd	l	m
Z
 d
d Zde_W n eyN   dZ Y nw Y nw Y nw ddlmZ dddZe soejZdddZee_dS dS )T    Nc                 C   s`   t |d t |d }}|| jd ks|| jd krtj}ntj}tj| d
 ||f|dS )Nr      uint8)interpolation)intshapecv2INTER_LINEAR
INTER_AREAresizeastype)picnewsizelxlyr    r   J/var/www/html/venv/lib/python3.10/site-packages/moviepy/video/fx/resize.pyresizer   s   r   r   )Imagec                 C   s~   t tt|d d d }| j}t|dkr!|d |d |d f}n|d |d f}t| }||d d d tj}t	
|S )N   r   r      )listmapr   r   lenr   	fromarrayr
   	ANTIALIASnparray)r   r   r   newshapepilimresized_pilr   r   r   r      s   

PIL)imresizec                 C   s   t | tt|d d d S )Nr   )r"   r   r   )r   r   r   r   r   <lambda>0   s    r#   ScipyFapply_to_maskc                    sD  | j \ dur@ fddtdr;fdd| jr&fdd}nfdd}| j|d	|r7d
gdS g dS n;dur^tdrU fdd}t| |S    gndur{tdrsfdd}t| |S    g| jrfdd}nfdd}| |}|r| jdurt| jdd|_|S )a   
    Returns a video clip that is a resized version of the clip.
    
    Parameters
    ------------
    
    newsize:
      Can be either 
        - ``(width,height)`` in pixels or a float representing
        - A scaling factor, like 0.5
        - A function of time returning one of these.
            
    width:
      width of the new clip in pixel. The height is then computed so
      that the width/height ratio is conserved. 
            
    height:
      height of the new clip in pixel. The width is then computed so
      that the width/height ratio is conserved.
    
    Examples
    ----------
             
    >>> myClip.resize( (460,720) ) # New resolution: (460,720)
    >>> myClip.resize(0.6) # width and heigth multiplied by 0.6
    >>> myClip.resize(width=800) # height computed automatically.
    >>> myClip.resize(lambda t : 1+0.02*t) # slow swelling of the clip
    
    Nc                    s"   t | ttfr|  |   gS | S N)
isinstancer   float)ns)hwr   r   trans_newsize`   s   zresize.<locals>.trans_newsize__call__c                    s    | S r'   r   t)r   r-   r   r   r#   i   s    zresize.<locals>.<lambda>c                    s$   dt d| | d | d S )N      ?   r   r   r   gfr0   newsize2r   r   r#   m   s
    c                    s   t | |d |S Nr   r3   r4   r6   r   r   r#   q   s    Tmask)keep_durationapply_toc                    s   dt |    S Nr1   )r   r/   )r+   heightr   r   r#      s    c                    s   d|    S r<   r   r/   )r,   widthr   r   r#          c                    s   dt d|  d  d S )Nr1   r2   r   g     o@r3   r   r   r   r   r#      s    c                    s   t | d S r8   r3   r@   rA   r   r   r#      r?   Fr%   )sizehasattrismaskflr
   fl_imager9   )clipr   r=   r>   r&   funrE   newclipr   )r+   r=   r   r7   r-   r,   r>   r   r
   =   s>   







r
   c                 C   s   t d)Nz&fx resize needs OpenCV or Scipy or PIL)ImportError)rG   r   r=   r>   r   r   r   r
      s   )NNNT)NNN)resize_possibler   numpyr   r   originrJ   r!   r   
scipy.miscr"   moviepy.decoratorsr&   r
   __doc__docr   r   r   r   <module>   s>    


%
c

