3

U'ícî6ã
@s¨ddlZddlZddlZddlZddlmZdddgZdZdZdZ	dZ
dZd	ZdZ
dZd
ZdZdZdZd	d	dd
d
d	d	dd
d
d
d
dœZdd„Zdd„Zdd„Zdd„ZdS)éN)ÚElementTreeÚgetÚgetDPIÚ__version__z1.4.1ééééééé)rrrr	r
réré	é
éécCsÜ|tkrt|ddƒS|tkr0t|ddƒS|tkrHt|ddƒS|tkr`t|ddƒS|tkrxt|ddƒS|tkrt|ddƒS|tkr¨t|ddƒS|tkr¸|d	S|t	krÈ|d
S|t
krØ|dS|S)Ngê5‡µB¢ú>gà?g²t±i¥0?g¢ÑÄÎd?g¦
F%uš?g¨ÆK7‰AÐ?gR¸…ëQ@gffffff9@éþiì	i8c)Ú_UNIT_KMÚintÚ
_UNIT_100MÚ	_UNIT_10MÚ_UNIT_1MÚ
_UNIT_10CMÚ_UNIT_CMÚ_UNIT_MMÚ_UNIT_0_1MMÚ_UNIT_0_01MMÚ_UNIT_UM)ZdensityÚunit©rú./tmp/pip-build-gk9425m9/imagesize/imagesize.pyÚ
_convertToDPI*s*r!cCsÐtjd|ƒ}|std|ƒ‚|jƒ\}}|dkr8t|ƒS|dkrPt|ƒddS|dkrlt|ƒdddS|d	kr€t|ƒdS|d
kr˜t|ƒddS|dkr°t|ƒddS|d
krÀt|ƒStd|ƒ‚dS)Nz(\d+(?:\.\d+)?)?([a-z]*)$zunknown length value: %sÚÚcmé`gR¸…ëQ@ÚmmrÚinZpcrÚptZpxzunknown unit type: %s)ÚreÚmatchÚ
ValueErrorÚgroupsÚfloat)ÚvalueÚmatchedÚlengthrrrr Ú_convertToPxBs&r0cCsVdU}dV}t|tjƒr|}n
t|dƒ}z|jdƒ}t|ƒ}|dkr’|dd…dWkr’ytjd	|dd…ƒ\}}Wntjk
rŒt	d
ƒ‚YnXn®|dkrô|j
dƒrô|d
d…dkrôytjd|dd…ƒ\}}Wntjk
rît	dƒ‚YnXnL|dkrL|j
dƒrLytjd|dd…ƒ\}}Wn t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@|dd
…dFkr@|d
d…dGkr€tjdH|dIdJ…ƒ\}}nÀ|d
d…dKkrÌtjdL|ddM…dNƒd}tjdL|dMdJ…dNƒd}nt|d
d…dOkr8|dPdQ…}|ddR@d>|dBd}|d'dS@d>|dd>B|dd@d?Bd}nt	dTƒ‚Wd|jƒX||fS)fz 
    Return (width, height) for a given img file content
    no requirements
    :type filepath: Union[bytes, str, pathlib.Path]
    :rtype Tuple[int, int]
    rÚrbérNróGIF87aóGIF89az<hhzInvalid GIF fileés‰PNG

résIHDRz>LLzInvalid PNG filerrsÿØréÀéÏéÄéÈéÌéÿz>Hz>HHr	zInvalid JPEG filesjP  
‡
é0zInvalid JPEG2000 filesMM*z>Lz>HHLLériz?Invalid TIFF file: width column data type should be SHORT/LONG.iz@Invalid TIFF file: height column data type should be SHORT/LONG.z?Invalid TIFF file: width and/or height IDS entries are missing.sII*z<Lz<Hz<HHLLsII+z@Invalid BigTIFF file: Expected offset to be 8, found {} instead.z<Qz<HHQQézBInvalid BigTIFF file: width and/or height IDS entries are missing.r
s<?xmls<svgizutf-8z[^-]width="(.*?)"z[^-]height="(.*?)"zInvalid SVG fileóPs123456ózInvalid Netpbm fileó#z&Invalid character found on Netpbm filesRIFFsWEBPsVP8 z<HHéésVP8Xz<IéósVP8Lééé?ézUnsupported WebP fileéÿÿÿÿrK)r3r4)r9r:r;rKrKrKrKrKrKrKrKrKrKrKrKrK)Ú
isinstanceÚioÚBytesIOÚopenÚreadÚlenÚstructÚunpackÚerrorr*Ú
startswithÚseekÚordÚ	TypeErrorÚrangerÚformatÚdecoder(ÚsearchÚgroupÚ	Exceptionr0ÚisspaceÚreadlineÚisdigitÚappendÚosÚSEEK_CURÚclose)ÚfilepathÚheightÚwidthÚfhandleÚheadÚsizeÚftypeÚbyteÚoffsetZifdsizeÚiÚtagÚdatatypeÚcountÚdataZbytesize_offsetÚsizesZnext_chrÚbrrr rZs$

"
*
 















"


$






2
cCs8d'}d(}t|tƒst|ƒ}t|dƒ}|jdƒ}t|ƒ}|dkrV|dd…d)krVnÐ|dkof|jd	ƒrfd
}|d
d…}xæ|dd
…}|dkrôytjd
|d
d…ƒ\}	}
}Wntj	k
rÌt
dƒ‚YnX|rèt|	tƒ}t|
tƒ}n|	}|
}Pq||dkrPq|ytjd|dd…ƒ\}Wn tj	k
r<t
dƒ‚YnX||d7}|j
|ƒ|jdƒ}q|WnÀ|dkr¢|jdƒr¢yþ|j
dƒd}d}
xæd|
ko¨dknsx|
dkr|j
ddƒtjd|jdƒƒ\}}	}
|dksò|dkrü|	}|
}n|dkrt|	tƒ}t|
tƒ}P|j
|dƒ|jdƒ}xt|ƒdkrP|jdƒ}q4Wt|ƒ}
tjd|jdƒƒdd}q”WWn tj	k
rœt
dƒ‚YnXn„|dkr&|jdƒr&|j
d ƒtjd|jdƒƒdd
}|j
ddƒd!}yxl|dkr\|jd
ƒ}|dd…}|d"kr*d#}|d
8}Ptjd|dd…ƒ\}|j
|d
dƒ||8}qòW|rôxŽ|dkrò|jd
ƒ}|dd…}|d$krÀtjd%|jdƒƒ\}
}	}}t|	|ƒ}t|
|ƒ}Ptjd|dd…ƒ\}|j
|d
dƒ||8}qfWWn.tj	k
r$}zt
d&ƒ‚WYdd}~XnXWdQRX||fS)*zŸ
    Return (x DPI, y DPI) for a given img file content
    no requirements
    :type filepath: Union[bytes, str, pathlib.Path]
    :rtype Tuple[int, int]
    rr1r5rNróGIF87aóGIF89as‰PNG

rr	spHYsz>LLBzInvalid PNG filesIDATz>LrrérsÿØr7r8éàr
z>BHHr
r<z>HzInvalid JPEG filesjP  
‡
é Fsres Tsresdz>HHBBzInvalid JPEG2000 filerKrK)rvrw)rLÚbytesÚstrrOrPrQrUrRrSrTr*r!rrVrrW)rfZxDPIZyDPIrirjrkÚchunkOffsetÚchunkZ	chunkTypeZxDensityZyDensityrZdataSizerlrmZ
headerSizeZfoundResBoxZ	boxHeaderZboxTypeZboxSizeZyUnitZxUnitÚerrr rs²










$






$éýÿÿÿéþÿÿÿrK)rMrcr(rRZ	xml.etreerÚ__all__rrrrrrrrrrrZ
_UNIT_INCHZ_TIFF_TYPE_SIZESr!r0rrrrrr Ú<module>sD
=