
    ]i              	       *    d Z ddlZddedededefdZy)	uG   Image compression utility — resize and compress before GDrive upload.    N
file_bytesmax_pxqualityreturnc                    ddl m} |j                  t        j                  |             }|j
                  dvr|j                  d      }|j                  \  }}t        ||      |kD  rE|t        ||      z  }|j                  t        ||z        t        ||z        f|j                        }t        j                         }|j                  |d|d       |j                         S )u   
    Resize image to max_px on longest side (maintain aspect ratio) and
    compress to JPEG at given quality. Returns compressed JPEG bytes.

    Typical result: 100–300 KB vs original 3–8 MB.
    r   )Image)RGBLr	   JPEGT)formatr   optimize)PILr   openioBytesIOmodeconvertsizemaxresizeintLANCZOSsavegetvalue)	r   r   r   r   imgwhratiobufs	            1/var/www/html/spbu.com/backend/app/utils/image.pycompress_imager!      s     
**RZZ
+
,C xx|#kk%  88DAq
1ay6Q"jj#a%i.#a%i.95==I
**,CHHS4H@<<>    )i   K   )__doc__r   bytesr   r!    r"   r    <module>r'      s-    M 	u c 3 PU r"   