
    ,hN#                         d Z ddlmZ ddlZddlZ	 ddlmZ ddl	m
Z
mZ ddlmZ ddlmZ ddlmZ  G d	 d
e      Z G d de      Zy# e$ r ddlZY <w xY w)zImagePart and related objects.    )divisionN)Image)BytesIO	is_string)Part)image_content_types)lazypropertyc                        e Zd ZdZd fd	Zed        Zed        Zed        Z	ed        Z
d Zed        Zed	        Zed
        Zed        Z xZS )	ImagePartzvAn image part.

    An image part generally has a partname matching the regex
    `ppt/media/image[1-9][0-9]*.*`.
    c                 @    t         t        |   ||||       || _        y N)superr   __init__	_filename)selfpartnamecontent_typepackageblobfilename	__class__s         R/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/pptx/parts/image.pyr   zImagePart.__init__   s    i',N!    c                      | |j                  |j                        |j                  ||j                  |j                        S )zcReturn new |ImagePart| instance containing `image`.

        `image` is an |Image| object.
        )next_image_partnameextr   r   r   )clsr   images      r   newzImagePart.new    s=     ''		2JJNN
 	
r   c                 P    | j                   d| j                  z  S | j                   S )al  
        The filename associated with this image, either the filename of
        the original image or a generic name of the form ``image.ext``
        where ``ext`` is appropriate to the image file format, e.g.
        ``'jpg'``. An image created using a path will have that filename; one
        created with a file-like object will have a generic name.
        zimage.%s)r   r   r   s    r   desczImagePart.desc.   s'     >>!((~~r   c                 .    | j                   j                  S )zF
        Return file extension for this image e.g. ``'png'``.
        )r   r   r!   s    r   r   zImagePart.ext<   s    
 }}   r   c                 B    t        | j                  | j                        S )zL
        An |Image| object containing the image in this image part.
        )r   r   r"   r!   s    r   r   zImagePart.imageC   s    
 TYY		**r   c                    | j                   \  }}|
||}|}||fS |2t        |      t        |      z  }t        t        ||z              }||fS |.t        |      t        |      z  }t        t        ||z              }||fS )a  
        Return scaled image dimensions in EMU based on the combination of
        parameters supplied. If *scaled_cx* and *scaled_cy* are both |None|,
        the native image size is returned. If neither *scaled_cx* nor
        *scaled_cy* is |None|, their values are returned unchanged. If
        a value is provided for either *scaled_cx* or *scaled_cy* and the
        other is |None|, the missing value is calculated such that the
        image's aspect ratio is preserved.
        )_native_sizefloatintround)r   	scaled_cx	scaled_cyimage_cximage_cyscaling_factors         r   scalezImagePart.scaleJ   s     "..(!2 I I )## "9-h?NE(^";<=I
 )##	 "9-h?NE(^";<=I)##r   c                 \    t        j                  | j                        j                         S )z
        The SHA1 hash digest for the image binary of this image part, like:
        ``'1be010ea47803b00e140b852765cdf84f491da47'``.
        hashlibsha1_blob	hexdigestr!   s    r   r3   zImagePart.sha1b   s      ||DJJ'1133r   c                 X    t         j                  | j                        }|j                  S )zv
        A (horz_dpi, vert_dpi) 2-tuple (ints) representing the dots-per-inch
        property of this image.
        )r   	from_blobr   dpir   r   s     r   _dpizImagePart._dpij   s      		*yyr   c                 j    d}| j                   \  }}| j                  \  }}||z  |z  }||z  |z  }||fS )z
        A (width, height) 2-tuple representing the native dimensions of the
        image in EMU, calculated based on the image DPI value, if present,
        assuming 72 dpi as a default.
        i )r:   _px_size)r   EMU_PER_INCHhorz_dpivert_dpiwidth_px	height_pxwidthheights           r   r&   zImagePart._native_sizes   sM     !YY("mm)x'(2	)H4f}r   c                 X    t         j                  | j                        }|j                  S )zh
        A (width, height) 2-tuple representing the dimensions of this image
        in pixels.
        )r   r7   r   sizer9   s     r   r<   zImagePart._px_size   s      		*zzr   r   )__name__
__module____qualname____doc__r   classmethodr   propertyr"   r   r   r/   r	   r3   r:   r&   r<   __classcell__r   s   @r   r   r      s    " 
 
   ! ! + +$0 4 4      r   r   c                        e Zd ZdZ fdZedd       Zed        Zed        Z	e
d        Ze
d        Ze
d        Zed	        Ze
d
        Ze
d        Zed        Ze
d        Z xZS )r   zIImmutable value object representing an image such as a JPEG, PNG, or GIF.c                 F    t         t        |           || _        || _        y r   )r   r   r   r4   r   )r   r   r   r   s      r   r   zImage.__init__   s    eT#%
!r   c                      | ||      S )zCReturn a new |Image| object loaded from the image binary in *blob*. )r   r   r   s      r   r7   zImage.from_blob   s     4""r   c                 N   t        |      rEt        |d      5 }|j                         }ddd       t        j                  j                  |      }n8t        t        |d            r|j                  d       |j                         }d}| j                  |      S # 1 sw Y   sxY w)z
        Return a new |Image| object loaded from *image_file*, which can be
        either a path (string) or a file-like object.
        rbNseekr   )
r   openreadospathbasenamecallablegetattrrT   r7   )r   
image_filefr   r   s        r   	from_filezImage.from_file   s     Z j$'  1vvx ww''
3H 
F34"??$DH}}T8,,   s   BB$c                     | j                   S )z<
        The binary image bytestream of this image.
        )r4   r!   s    r   r   z
Image.blob   s    
 zzr   c                 (    t         | j                     S )zA
        MIME-type of this image, e.g. ``'image/jpeg'``.
        )r   r   r!   s    r   r   zImage.content_type   s    
 #488,,r   c                 >    d fd} || j                   d         S )z
        A (horz_dpi, vert_dpi) 2-tuple specifying the dots-per-inch
        resolution of this image. A default value of (72, 72) is used if the
        dpi is not specified in the image file.
        c                     	 t        t        t        |                   }|dk  s|dkD  rd}|S # t        t        f$ r d}Y |S w xY w)z
            Return an integer dots-per-inch value corresponding to *dpi*. If
            *dpi* is |None|, a non-numeric type, less than 1 or greater than
            2048, 72 is returned.
               i   H   )r(   r)   r'   	TypeError
ValueError)r8   int_dpis     r   rg   zImage.dpi.<locals>.int_dpi   sS    eE#J/0Q;'D. G N z* Ns   )- AAc                 R    t        | t              r | d          | d         fS y)a  
            Return a (horz_dpi, vert_dpi) 2-tuple corresponding to *pil_dpi*,
            the value for the 'dpi' key in the ``info`` dict of a PIL image.
            If the 'dpi' key is not present or contains an invalid value,
            ``(72, 72)`` is returned.
            r   rc   )rd   rd   )
isinstancetuple)pil_dpirg   s    r   normalize_pil_dpiz$Image.dpi.<locals>.normalize_pil_dpi   s/     '5)
+WWQZ-@AAr      
_pil_props)r   rl   rg   s     @r   r8   z	Image.dpi   s#    			 !!344r   c                 ~    ddddddd}| j                   }||vr d}t        ||j                         |fz        ||   S )	a  
        Canonical file extension for this image e.g. ``'png'``. The returned
        extension is all lowercase and is the canonical extension for the
        content type of this image, regardless of what extension may have
        been used in its filename, if any.
        bmpgifjpgpngtiffwmf)BMPGIFJPEGPNGTIFFWMFz7unsupported image format, expected one of: %s, got '%s')_formatrf   keys)r   ext_mapformattmpls       r   r   z	Image.ext   sZ     
  LDTW\\^V$<<==vr   c                     | j                   S )z
        The filename from the path from which this image was loaded, if
        loaded from the filesystem. |None| if no filename was used in
        loading, such as when loaded from an in-memory stream.
        )r   r!   s    r   r   zImage.filename   s     ~~r   c                 \    t        j                  | j                        j                         S )z4
        SHA1 hash digest of the image blob
        r1   r!   s    r   r3   z
Image.sha1   s     
 ||DJJ'1133r   c                      | j                   d   S )zf
        A (width, height) 2-tuple specifying the dimensions of this image in
        pixels.
        rc   rn   r!   s    r   rE   z
Image.size  s     q!!r   c                      | j                   d   S )zA
        The PIL Image format of this image, e.g. 'PNG'.
        r   rn   r!   s    r   r}   zImage._format  s    
 q!!r   c                     t        | j                        }t        j                  |      }|j                  }|j
                  \  }}|j                  j                  d      }|j                          |||f|fS )z
        A tuple containing useful image properties extracted from this image
        using Pillow (Python Imaging Library, or 'PIL').
        r8   )	r   r4   	PIL_ImagerU   r   rE   infogetclose)r   stream	pil_imager   r@   rA   r8   s          r   ro   zImage._pil_props  sh     $NN6*	!!'nn)nn  '9-s33r   r   )rF   rG   rH   rI   r   rJ   r7   r^   rK   r   r	   r   r8   r   r   r3   rE   r}   ro   rL   rM   s   @r   r   r      s    S"
 # # - -(   - -  5  5D  *   4 4 " " " " 4 4r   r   )rI   
__future__r   r2   rW   PILr   r   ImportErrorpptx.compatr   r   pptx.opc.packager   pptx.opc.specr   	pptx.utilr	   r   objectrQ   r   r   <module>r      s[    %   	& + ! - "u upT4F T4C  s   A	 		AA