
    +j                    f    S r SSKJr  SSKrSSKJr  \R                  " \5      r S     SS jjr	g)zImage dimension extraction for asset ingest.

Reads only the image header via Pillow to capture width/height cheaply,
without a full pixel decode. Returns a metadata dict suitable for merging
into ``AssetReference.system_metadata``.
    )annotationsN)Anyc                   Ub  UR                  S5      (       d  g SSKJnJn   UR                  U 5       nUR                  u  pVSSS5        [        W[        5      (       a!  [        W[        5      (       a  US::  d  US::  a  gSXVS.$ ! [         a    [
        R                  SU 5         gf = f! , (       d  f       Np= f! [        U[        4 a   n[
        R                  SX5         SnAgSnAff = f)	a  Extract image dimensions for the file at ``file_path``.

Args:
    file_path: Absolute path to a file on disk.
    mime_type: Optional MIME type hint. When provided and not prefixed
        with ``image/``, extraction is skipped without touching the file.

Returns:
    ``{"kind": "image", "width": W, "height": H}`` when the file is a
    recognizable image with positive dimensions, otherwise ``None``.

The dict shape is intended to be merged into ``system_metadata`` so the
asset response surfaces ``metadata.kind`` plus dimension fields for image
assets. Forward-compatible: future media kinds (e.g. ``"video"`` with
duration/fps) can extend this shape without schema changes.
Nzimage/r   )ImageUnidentifiedImageErrorz@Pillow not available; skipping image dimension extraction for %sz+Failed to read image dimensions from %s: %simage)kindwidthheight)
startswithPILr   r   ImportErrorloggerdebugopensizeOSError
ValueError
isinstanceint)	file_path	mime_typer   r   imgr
   r   excs           D/home/wildlama/comfy/ComfyUI/app/assets/services/image_dimensions.pyextract_image_dimensionsr      s    & Y%9%9(%C%C5ZZ	"cHHME # uc""&#&&A:Q;e>>1  N	
  #"+Z8 99	
 	sE   B	 C  B/C  	 B,+B,/
B=9C  =C   C1C,,C1)N)r   strr   z
str | Nonereturnzdict[str, Any] | None)
__doc__
__future__r   loggingtypingr   	getLogger__name__r   r        r   <module>r'      sG    #  			8	$ -10?0?)0?0?r&   