
    %j&                     B    d dl Z d dlZd dlZd dlT d dlmZ dedefdZdS )    N)*)MinimaxRequestError	image_urlreturnc                    |                      d          r
| dd         } |                      d          r| S |                      d          r	 t          j        |           }|                                 |j        }|j                            dd                                          }d|v sd	|v rd}nd
|v rd
}n	d|v rd}nd}t          j        |          	                    d          }d| d| S # t          j
        $ r$}t          dt          |                     d}~ww xY wt          j                            |           st          d|            	 t!          | d          5 }|                                }d}|                                                     d          rd
}nS|                                                     d          rd}n)|                                                     d          rd}t          j        |          	                    d          }d| d| cddd           S # 1 swxY w Y   dS # t&          $ r$}t          dt          |                     d}~ww xY w)aG  
    Process image URL and convert to base64 data URL format.
    
    This function handles three types of image inputs:
    1. HTTP/HTTPS URLs: Downloads the image and converts to base64
    2. Base64 data URLs: Passes through as-is
    3. Local file paths: Reads the file and converts to base64
    
    Args:
        image_url (str): The image URL, data URL, or local file path
        
    Returns:
        str: Base64 data URL in format "data:image/{format};base64,{data}"
        
    Raises:
        MinimaxRequestError: If image cannot be downloaded, read, or processed
    @   Nzdata:)zhttp://zhttps://zcontent-type jpegjpgpngwebpzutf-8zdata:image/z;base64,z#Failed to download image from URL: z!Local image file does not exist: rbz.pngz.webp)z.jpgz.jpegz!Failed to read local image file: )
startswithrequestsgetraise_for_statuscontentheaderslowerbase64	b64encodedecodeRequestExceptionr   strospathexistsopenreadendswithIOError)r   image_response
image_datacontent_typeimage_formatbase64_dataefs           c/home/kuhnn/.cache/uv/archive-v0/2m3GSyFXjlQcJqu5/lib/python3.11/site-packages/minimax_mcp/utils.pyprocess_image_urlr+   	   s*   & C   "abbM	 G$$  344 /T	V%\)44N++---'/J *155nbIIOOQQL%%,)>)>%,&&$<''%  & !*:66==gFFKDDD{DDD( 	V 	V 	V%&TCPQFF&T&TUUU	V
 w~~i(( 	W%&U)&U&UVVV	Ti&& I!VVXX
  &??$$--f55 *#(LL__&&//88 *#)LL__&&//0ABB *#)L$.z::AA'JJH\HH;HHI I I I I I I I I I I I I I I I I I  	T 	T 	T%&R#a&&&R&RSSS	TsV   B%C3 3D&D!!D&I +CH:-I :H>>I H>I 
I5I00I5)r   r   r   minimax_mcp.constminimax_mcp.exceptionsr   r   r+        r*   <module>r0      sz    				       7 7 7 7 7 7JT JT JT JT JT JT JT JTr/   