
    MgB                     t    S SK Jr  S SKrS SKJrJr  S SKJr  \" S5      \" S5       " S S5      5       5       rg)	    )ImageN)pluginalias)Forezimage compressorimgcompressorc                   R    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rSS jrSrg)ImageCompressor   zA tool to compress images.c                 6    S U l         SSSS.U l        SU l        g )NJPEGPNG)z.jpgz.jpegz.pngcompressed_)qualityformatsprefix)selfs    C/Users/admin/workspace/ai/Jarvis/jarviscli/plugins/imgcompressor.py__init__ImageCompressor.__init__   s     &G#    c                 &    U R                  U5        g )N)img_compressor)r   jarvisss      r   __call__ImageCompressor.__call__   s    F#r   c                    UR                  S5        UR                  S5        UR                  SSU R                   3-   5         U R                  U5        UR                  S5      nUR	                  5       nUS:X  d  US:X  d  US:X  a!  UR                  S	[
        R                  5        gU R                  U5      U l        US
:X  a  U R                  U5        O*US:X  a  U R                  U5        OUR                  5         M  M  )z]Main function.

This function is the main menu, that will run
until the user says otherwise.
 z(This tool will help you compress a imagez.The given images will be compressed and saved z$on the same directory with a prefix zYour choice: qquit3zSee you next time :D12N)sayr   available_optionsinputlowerr   CYANquality_optionr   compress_single_imagecompress_multiple_imagesincorrect_option)r   r   
user_inputs      r   r   ImageCompressor.img_compressor   s     	

2

=>

<4T[[MBC	
 ""6*o6J#))+JS J&$8J#<M

1499=..v6DL S **62 s"--f5 '')- r   c                 *    UR                  S5      n[        R                  R                  U5      (       a*  UR	                  [        U R                  5      5      (       a  O"UR                  S[        R                  5        M  U R                  X5        g)z2Compress a single image, specifying the full path.z"Enter the full path of the image: =Opps! Looks like you entered an invalid path. Kindly Re-enterN)r&   ospathisfileendswithtupler   r$   r   REDimg_compress)r   r   
image_paths      r   r*   %ImageCompressor.compress_single_image9   su     46Jww~~j))j.A.A%BU.V.V

SUYU]U]_  	&-r   c                      UR                  S5      n[        R                  R                  U5      (       a  O"UR	                  S[
        R                  5        MX  U R                  X5        g)zMCompress multiple images on a folder, specifying the full path to the folder.z!Enter the full path of a folder: r0   N)r&   r1   r2   isdirr$   r   r6   folder_images_compress)r   r   folder_paths      r   r+   (ImageCompressor.compress_multiple_imagesF   s\      ,,35Kww}}[))

SUYU]U]_  	##F8r   c                     UR                  S5        UR                  S5        UR                  S5        UR                  S5        g)z@
Message displayed to prompt the user about compressing
images.
z$Select one of the following options:z1: Compress a single imagez"2: Compress all images of a folderz3: QuitN)r$   r   r   s     r   r%   !ImageCompressor.available_optionsS   s7     	

9:

/0

78

9r   c           	      F    [        UR                  S[        SSS9S-
  5      $ )zcGet desired image quality.

Message displayed to prompt the user about the quality
of compression.
zP
Enter desired quality of compression (0-100 where 100 is maximum compression): r   d   )promptrtyperminrmax)absinput_numberintr@   s     r   r)   ImageCompressor.quality_option^   s:     j	   
 
 	
r   c                 0   [         R                  " U5       H\  nUR                  [        U R                  5      5      (       d  M.  U R                  U[         R                  R                  X#5      SS9  M^     UR                  S[        R                  5        g)zkCompress all images in a folder.

This function is used to compress all the images
in a given folder path.
T)from_folderz?Your images in the provided folder were compressed successfullyN)r1   listdirr4   r5   r   r7   r2   joinr$   r   GREEN)r   r   r=   images       r   r<   &ImageCompressor.folder_images_compressn   sn     ZZ,E~~eDLL122!!BGGLL<$ " P -
 	

Mtzz	
r   c           	         [         R                  " USS9nUR                  [        R                  R                  [        R                  R                  U5      U R                  [        R                  R                  U5      -   5      U R                  R                  [        R                  R                  U5      S   5      SU R                  S9  U(       d!  UR                  S[        R                  5        gg)zSave and compress image.

Save and compress the image to same location as the original
with the specified quality of compression.
r)mode   T)optimizer   z&Your image was compressed successfullyN)r   opensaver1   r2   rO   dirnamer   basenamer   getsplitextr   r$   r   rP   )r   r   img_pathrM   pictures        r   r7   ImageCompressor.img_compress~   s     **XC0RWW\\"''//(";T[[277K[K[\dKe=ef\\%%bgg&6&6x&@&CD"!\\ 	 	+
 JJ?L r   )r   r   r   N)F)__name__
__module____qualname____firstlineno____doc__r   r   r   r*   r+   r%   r)   r<   r7   __static_attributes__ r   r   r	   r	      s6     %$
$#J.9	
 
 Mr   r	   )PILr   r1   r   r   coloramar   r	   rg   r   r   <module>rj      sC     	    DM DM  DMr   