
    %^g=                         d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ  ej                  d      Z G d	 d
e      Zy)    N)OrderedDict)NamedTemporaryFile)	smart_str)
EXTENSIONS)settings)
EngineBasez^(?:.+) (?P<x>\d+)x(?P<y>\d+)c                   @    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)EnginezC
    Image object is a dict with source path, options and size
    c                    t         j                  j                  d      }|j                  |d          |d   D ]5  }|d   |   }|j                  d|z         |"|j                  d|z         7 dt        |d      z  }g }|d   d	k(  r1|j                  d
t         j                        r|j                  d       |d   r|d   d	k(  r|j                  d|d   z         t        |d      5 }	|j                  d       |j                  |	j                  ddj                  |      z  z          t        t        |      }t        j                  |t        j                  t        j                        }
|
j                          |
j!                         \  }}|rt#        |      |j%                  |	j'                                ddd       y# 1 sw Y   yxY w)z,
        Writes the thumbnail image
         sourceoptionsz--%sNz%sz.%sformatJPEGprogressive	interlacequalityzQ=%drb)suffixmodez-oz[%s],stdoutstderr)r   THUMBNAIL_VIPSTHUMBNAILsplitappendr   getTHUMBNAIL_PROGRESSIVEr   namejoinmapr   
subprocessPopenPIPEwaitcommunicate	Exceptionwriteread)selfimager   	thumbnailargskvr   write_optionsfppouterrs                o/var/www/html/webapps/promises/venv/lib/python3.12/site-packages/sorl/thumbnail/engines/vipsthumbnail_engine.pyr)   zEngine.write   s   
 //55c:E(O$y! 	&Ai #AKK
#}D1H%		& GH$5668&7;;x==,?  -9x F*$$Vgi.@%@AvD9 	'R KKKK&388M+B"BBCy$'D  joojooVAFFH}}HCn$OOBGGI&	' 	' 	's   ,CG

Gc                 4    t        j                  |d          y )Nr   )osremover+   r,   s     r6   cleanupzEngine.cleanup>   s    
		%/"    c                     t        dd      5 }|j                  |j                                ddd       j                  t	               ddS # 1 sw Y   !xY w)zM
        Returns the backend image objects from a ImageFile instance
        wbF)r   deleteN)r   r   size)r   r)   r*   r    r   )r+   r   r2   s      r6   	get_imagezEngine.get_imageA   sJ      T%8 	$BHHV[[]#	$''kmTJJ	$ 	$s    AAc                    |d   t         j                  j                  d      }|j                  |d          t	        j
                  |t        j                  t        j                        }|j                          t        j                  t        |j                  j                                     }t        |j                  d            t        |j                  d            f|d<   |d   S )z?
        Returns the image width and height as a tuple
        r@   r   r   r   xy)r   THUMBNAIL_VIPSHEADERr   r   r#   r$   r%   r&   size_rematchstrr   r*   intgroup)r+   r,   r.   r3   ms        r6   get_image_sizezEngine.get_image_sizeI   s     = 0066s;DKKh(  joojooVAFFHc!((--/23A-s1773</@@E&MV}r<   c                    t        d      5 }|j                  |       |j                          t        j                  j                  d      }|j                  |j                         t        j                  |t        j                  t        j                        }|j                         }ddd       |dk(  S # 1 sw Y   dk(  S xY w)z
        vipsheader will try a lot of formats, including all those supported by
        imagemagick if compiled with magick support, this can take a while
        r>   )r   r   r   Nr   )r   r)   flushr   rE   r   r   r    r#   r$   r%   r&   )r+   raw_datar2   r.   r3   retcodes         r6   is_valid_imagezEngine.is_valid_imageV   s    
  T* 	bHHXHHJ0066s;DKK   joojooVAffhG	 !|	 !|s   B B::Cc                     d |d   d<   |S )Nr   rotate r:   s     r6   _orientationzEngine._orientationd   s     &*i"r<   c                     |S )zc
        vipsthumbnail does not support greyscaling of images, but pretend it
        does
        rT   )r+   r,   
colorspaces      r6   _colorspacezEngine._colorspacek   s	    
 r<   c                 .    |d||d   d<   ||f|d<   |S )z0
        Does the resizing of the image
        rC   r   r@   rT   )r+   r,   widthheights       r6   _scalezEngine._scaler   s*     /4V#<i fr<   N)__name__
__module____qualname____doc__r)   r;   rA   rL   rQ   rU   rX   r\   rT   r<   r6   r
   r
      s1    ''R#Kr<   r
   )r8   rer#   collectionsr   django.core.files.tempr   django.utils.encodingr   sorl.thumbnail.baser   sorl.thumbnail.confr   sorl.thumbnail.engines.baser   compilerF   r
   rT   r<   r6   <module>ri      s?    	 	  # 5 + * ( 2
"**5
6hZ hr<   