
    +j                    V    d Z ddlmZ ddlZddlmZ  ej        e          Z	 dddZ	dS )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)Any	file_pathstr	mime_type
str | Nonereturndict[str, Any] | Nonec                   ||                     d          sdS 	 ddlm}m} n,# t          $ r t
                              d|            Y dS w xY w	 |                    |           5 }|j        \  }}ddd           n# 1 swxY w Y   n<# t          |t          f$ r'}t
                              d| |           Y d}~dS d}~ww xY wt          |t                    r!t          |t                    r|dk    s|dk    rdS d||dS )	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)r   r   r   r   imgr   r   excs           D/home/wildlama/comfy/ComfyUI/app/assets/services/image_dimensions.pyextract_image_dimensionsr       s   & Y%9%9(%C%Ct555555555   N	
 	
 	
 ttZZ	"" 	%cHME6	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%+Z8   99c	
 	
 	
 ttttt	 uc""&#&& A::Q;;tev>>>sK   $ %AAB	 &A=1B	 =BB	 BB	 	CB==C)N)r   r   r   r   r	   r
   )
__doc__
__future__r   loggingtypingr   	getLogger__name__r   r         r   <module>r)      sx     # " " " " "       		8	$	$ -10? 0? 0? 0? 0? 0? 0?r(   