
    iz              	          d Z ddlZddlmZ ddlZddlmZ ddZe	dk    r e
ej                  d	k     r ed
            ej        d           dZej        dd         Zer7ed                                         r ee                                          ZeD ]KZ	  eee           # e$ r  ede d           Y 'e$ rZ ede de d           Y dZ[BdZ[ww xY wdS dS )u$  
extract-colors.py — Extract dominant brand colors from logo images.
Usage:     python3 extract-colors.py <image_path> [num_colors]
Examples:  python3 extract-colors.py logo.png
           python3 extract-colors.py logo.png banner.png 8

Dependencies: Pillow, numpy (both available on VPS)
    N)Image)Counter      c                 f   t          j        |           }|                    d          }|                    ||ft           j                  }t          j        |                              dd          }g }|D ]}t          |d                   t          |d                   t          |d                   t          |d                   f\  }}	}
}|dk     r`|d	k    r|	d	k    r|
d	k    rs|d
z  d
z  |	d
z  d
z  |
d
z  d
z  }}}|	                    d|d|d|d           |st          d           dS t          |          }t          |          }t          d|  d           |                    |          D ]4\  }}t          d|                                 d||z  dz  dd           5dS )a  
    Extract dominant brand colors from a logo image.
    - Resizes image for performance
    - Removes transparent pixels
    - Skips near-white background pixels
    - Quantizes to reduce noise (rounds RGB to nearest 15)
    Returns list of (hex_color, percentage) tuples.
    RGBA   r            2         #02xz.  [No non-white, non-transparent pixels found]Nz
[]z  d   z.1f%)r   openconvertresizeLANCZOSnparrayreshapeintappendprintlenr   most_commonupper)
image_path
num_colorsr   img	img_smallpixelsfilteredprgbaqrqgqbtotalcounts	hex_colorcounts                      F/home/leo/projects/perfect-lhd/design-system/scripts/extract-colors.pyextract_brand_colorsr6      s    *Z
 
 C
++f

C

FF+U];;IXi  ((Q//FH 6 61YYAaD		3qt99c!A$ii?
1ar66s77q3ww1s772g^a2g^a2g^B4B44B44B4445555 ?@@@MMEXF	




"..z:: @ @	5>9??$$>>eC>>>>????@ @    __main__r   z:Usage: python3 extract-colors.py <image_path> [num_colors]r   
   r	   )r$   z[File not found: r   z[Error reading z: )r   r   )__doc__sysPILr   numpyr   collectionsr   r6   __name__r    argvr   exitnumpathsisdigitr   poppathFileNotFoundError	Exceptione r7   r5   <module>rK      s    


                !@ !@ !@ !@H z
s38}}qJKKK
CHQRRLE r""$$ c%))++ 2 2	2  #66666  	/ 	/ 	/E-d---..... 	2 	2 	2E0D00A00011111111	2 2 2s   B--C#C#CC#