from PIL import Image
im = Image.open('test.jpg')
im.save('test.png', format='PNG')
img = img.convert('RGB')
img.save('image_compressed.jpg', quality=50, optimize=True)
ou can also use other libraries and methods to compress images in Python,
such as zlib, pngquant, or GraphicsMagick
img = img.resize((200, 150), Image.LANCZOS)
The resampling filter determines how the pixels are interpolated when resizing the image. Some of the available filters are Image.NEAREST, Image.BILINEAR, Image.BICUBIC, and Image.LANCZOS. If you omit the filter, or if the image has mode “1” or “P”, it is set to Image.NEAREST by default. Otherwise, the default filter is Image.BICUBIC.
new_file_size = original_file_size * ((new_width / original_width) * (new_height / original_height)) * (new_bit_depth / original_bit_depth)
https://stackoverflow.com/questions/33901299/formula-to-calculate-file-size-of-jpeg-image-after-resizing
Comments
Post a Comment