o
    	Ð'fê	  ã                   @  sT   d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	m
Z
 G dd„ deƒZdS )	z7The proxy class for an image part, and related objects.é    )ÚannotationsN)ÚImage)ÚPart)ÚEmuÚInchesc                      s|   e Zd ZdZ	dd‡ fd
d„Zedd„ ƒZedd„ ƒZedd„ ƒZe	dd„ ƒZ
eddd„ƒZe	dd„ ƒZedd„ ƒZ‡  ZS )Ú	ImagePartzlAn image part.

    Corresponds to the target part of a relationship with type RELATIONSHIP_TYPE.IMAGE.
    NÚpartnameÚstrÚcontent_typeÚblobÚbytesÚimageúImage | Nonec                   s   t t| ƒ |||¡ || _d S ©N)Úsuperr   Ú__init__Ú_image)Úselfr   r
   r   r   ©Ú	__class__© úH/home/ubuntu/flask/venv/lib/python3.10/site-packages/docx/parts/image.pyr      s   
zImagePart.__init__c                 C  s    | j j}| j j}|| }t|ƒS )zkNative width of this image, calculated from its width in pixels and
        horizontal dots per inch (dpi).)r   Úpx_widthÚhorz_dpir   )r   r   r   Úwidth_in_inchesr   r   r   Ú
default_cx   s   zImagePart.default_cxc                 C  s$   | j j}| j j}d| | }t|ƒS )zkNative height of this image, calculated from its height in pixels and
        vertical dots per inch (dpi).iàó )r   Ú	px_heightr   r   )r   r   r   Úheight_in_emur   r   r   Ú
default_cy!   s   zImagePart.default_cyc                 C  s   | j dur	| j jS d| jj S )a?  Filename from which this image part was originally created.

        A generic name, e.g. 'image.png', is substituted if no name is available, for
        example when the image was loaded from an unnamed stream. In that case a default
        extension is applied based on the detected MIME type of the image.
        Nzimage.%s)r   Úfilenamer   Úext©r   r   r   r   r   *   s   
zImagePart.filenamec                 C  s   t ||j|j|ƒS )zZReturn an |ImagePart| instance newly created from `image` and assigned
        `partname`.)r   r
   r   )Úclsr   r   r   r   r   Ú
from_image6   s   zImagePart.from_imageÚreturnr   c                 C  s   | j d u rt | j¡| _ | j S r   )r   r   Ú	from_blobr   r!   r   r   r   r   <   s   
zImagePart.imagec                 C  s   | |||ƒS )zCalled by ``docx.opc.package.PartFactory`` to load an image part from a
        package being opened by ``Document(...)`` call.r   )r"   r   r
   r   Úpackager   r   r   ÚloadB   s   zImagePart.loadc                 C  s   t  | j¡ ¡ S )z0SHA1 hash digest of the blob of this image part.)ÚhashlibÚsha1Ú_blobÚ	hexdigestr!   r   r   r   r)   H   s   zImagePart.sha1r   )r   r	   r
   r	   r   r   r   r   )r$   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr   r   r   Úclassmethodr#   r   r'   r)   Ú__classcell__r   r   r   r   r      s$    ÿ




r   )r/   Ú
__future__r   r(   Údocx.image.imager   Údocx.opc.partr   Údocx.sharedr   r   r   r   r   r   r   Ú<module>   s    