XjEdZddlmZddlZddlZddlZddlmZmZddl m Z ddl m Z m Z mZmZGddZd d ZGd d Zy) zProvides objects that can characterize image streams. That characterization is as to content type and size, as a required step in including them in a document. ) annotationsN)IOTuple)UnrecognizedImageError)EmuInchesLength lazypropertyc@eZdZdZdfd ZeddZeddZedZ eddZ e dZ edZ edd Zedd Zedd Zedd Zedd ZeddZ d ddZe dZe d ddZxZS)ImagezgGraphical image stream such as JPEG, PNG, or GIF with properties and methods required by ImagePart.cTtt| ||_||_||_yN)superr __init___blob _filename _image_header)selfblobfilename image_header __class__s d/mnt/ssd/data/Dropbox/adrian/vault-secondbrain/venv/lib/python3.12/site-packages/docx/image/image.pyrzImage.__init__s& eT#% !)cPtj|}|j||S)z`Return a new |Image| subclass instance parsed from the image binary contained in `blob`.)ioBytesIO _from_stream)clsrstreams r from_blobzImage.from_blobs%D!--rcbt|tr\|}t|d5}|j}t j |}dddt jj|}n%|}|jd|j}d}|j|S#1swYaxYw)zReturn a new |Image| subclass instance loaded from the image file identified by `image_descriptor`, a path or file-like object.rbNr) isinstancestropenreadrrospathbasenameseekr)rimage_descriptorr)frr rs r from_filezImage.from_file#s & ,#DdD! *QvvxD) *ww''-H%F KKN;;=DHh77 * *s &B%%B.c|jS)zThe bytes of the image 'file'.)rrs rrz Image.blob4szzrc.|jjS)zIMIME content type for this image, e.g. ``'image/jpeg'`` for a JPEG image.)r content_typer0s rr2zImage.content_type9s!!...rc`tjj|jdddS)aThe file extension for the image. If an actual one is available from a load filename it is used. Otherwise a canonical extension is assigned based on the content type. Does not contain the leading period, e.g. 'jpg', not '.jpg'. N)r(r)splitextrr0s rextz Image.ext>s)ww/21266rc|jS)zpOriginal image file name, if loaded from disk, or a generic filename if loaded from an anonymous stream.)rr0s rrzImage.filenameHs~~rc.|jjSz,The horizontal pixel dimension of the image.)rpx_widthr0s rr:zImage.px_widthNs!!***rc.|jjSz*The vertical pixel dimension of the image.)r px_heightr0s rr=zImage.px_heightSs!!+++rc.|jjSzInteger dots per inch for the width of this image. Defaults to 72 when not present in the file, as is often the case. )rhorz_dpir0s rr@zImage.horz_dpiX !!***rc.|jjSzInteger dots per inch for the height of this image. Defaults to 72 when not present in the file, as is often the case. )rvert_dpir0s rrDzImage.vert_dpi`rArcFt|j|jz S)z}A |Length| value representing the native width of the image, calculated from the values of `px_width` and `horz_dpi`.)rr:r@r0s rwidthz Image.widthhsdmmdmm344rcFt|j|jz S)zA |Length| value representing the native height of the image, calculated from the values of `px_height` and `vert_dpi`.)rr=rDr0s rheightz Image.heightnsdnnt}}455rcZ|||j|jfS|=|Jt|t|jz }t|j|z}|9t|t|jz }t|j|z}t |t |fS)a?(cx, cy) pair representing scaled dimensions of this image. The native dimensions of the image are scaled by applying the following rules to the `width` and `height` arguments. * If both `width` and `height` are specified, the return value is (`width`, `height`); no scaling is performed. * If only one is specified, it is used to compute a scaling factor that is then applied to the unspecified dimension, preserving the aspect ratio of the image. * If both `width` and `height` are |None|, the native dimensions are returned. The native dimensions are calculated using the dots-per-inch (dpi) value embedded in the image, defaulting to 72 dpi if no value is specified, as is often the case. The returned values are both |Length| objects. )rFrHfloatroundr)rrFrHscaling_factors rscaled_dimensionszImage.scaled_dimensionsts$ =V^::t{{* * =% %%"6]U4;;-??N$**~56E >"5\E$**,==N4;;78F5z3v;&&rc\tj|jjS)z#SHA1 hash digest of the image blob.)hashlibsha1r hexdigestr0s rrPz Image.sha1s ||DJJ'1133rcNt|}|d|jz}||||S)zhReturn an instance of the |Image| subclass corresponding to the format of the image in `stream`.zimage.%s)_ImageHeaderFactory default_ext)rr rrrs rrzImage._from_streams3+62  !L$<$<.read_32s A{{2rr r[) docx.imagerdlen from_streamr) r rdrgheaderroffsetsignature_bytesend found_bytess rrSrSse%V_F(2+$V_s?++VC( / )??6* * + ! rc|eZdZdZd dZed dZed dZedZedZ edZ edZ y ) rVz>Base class for image header subclasses like |Jpeg| and |Tiff|.c<||_||_||_||_yr) _px_width _px_height _horz_dpi _vert_dpi)rr:r=r@rDs rrzBaseImageHeader.__init__s!#!!rcd}t|)zDAbstract property definition, must be implemented by all subclasses.zNcontent_type property must be implemented by all subclasses of BaseImageHeaderNotImplementedError)rmsgs rr2zBaseImageHeader.content_types_!#&&rctd)zDefault filename extension for images of this type. An abstract property definition, must be implemented by all subclasses. zMdefault_ext property must be implemented by all subclasses of BaseImageHeaderrxr0s rrTzBaseImageHeader.default_exts " [  rc|jSr9)rsr0s rr:zBaseImageHeader.px_widths~~rc|jSr<)rtr0s rr=zBaseImageHeader.px_heightsrc|jSr?)rur0s rr@zBaseImageHeader.horz_dpi ~~rc|jSrC)rvr0s rrDzBaseImageHeader.vert_dpirrN)r:rYr=rYr@rYrDrYrX) r\r]r^r_rrar2rTr:r=r@rDrrrVrVsH" ''   rrVrh)r_ __future__rrOrr(typingrrdocx.image.exceptionsr docx.sharedrrr r r rSrVrrrrs@ # 899S1S1l!"11r