o
    #S-                     @   s   d dl mZ d dlZz
d dlmZmZ W n ey%   d dlZd dlZY nw d dlm	Z	 d dl
mZ d dlmZ dZdd	 Zd
d Zdd ZdS )    )BytesION)ImageImageOps)default_storage)InMemoryUploadedFile)utils)K   r   c                 C   s*   z
t |   W d S  ty   tjw )N)r   openverifyIOErrorr   NotAnImageException)f r   T/var/www/html/kck/venv/lib/python3.10/site-packages/ckeditor/image/pillow_backend.pyimage_verify   s
   r   c                 C   s   t | }t tj| d }|dd }t| }t	|}|j
dvr+|d}t|tt	j}t }|j||d t|d ||t| d }|d t||S )N   /)LRGBr   )formatr   )r   get_thumb_filenameget_image_formatospathsplitextsplitr   r	   r   modeconvertr   fitTHUMBNAIL_SIZE	ANTIALIASr   saver   lengetvalueseek)	file_paththumbnail_filenamethumbnail_formatfile_formatimageimagefitthumbnail_io	thumbnailr   r   r   create_thumbnail   s(   






r-   c                 C   s0   t | }zt| W dS  ty   Y dS w )NFT)r   r	   r   r   )r%   r)   r   r   r   should_create_thumbnail8   s   
r.   )ior   os.pathr   PILr   r   ImportErrordjango.core.files.storager   django.core.files.uploadedfiler   ckeditorr   r   r   r-   r.   r   r   r   r   <module>   s    