Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of Image Compression in python3

Shulou Source: shulou.com Published: 2022-06-03 19:15:27 11月12日 Update

Editor to share with you the example analysis of picture compression in python3, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Code

From PIL import Image# channel conversion def change_image_channels (image, image_path): # 4 channel to 3 channel if image.mode = = 'RGBA': r, g, b, a = image.split () image = Image.merge ("RGB", (r, g) B) image.save (image_path) # 1 channel to 3 channel elif image.mode! = 'RGB': image = image.convert ("RGB") os.remove (image_path) image.save (image_path) return image # Image compression def image_compression (image): W, h = image.size print (w, h) image.thumbnail ((int (w / 1.1)) Int (h / 1. 1)) image.save (". / car.png") return image if _ _ name__ = = "_ _ main__": image = Image.open (". / timg.png") new_image = process_image_channels (image, ". / time.png") print (new_image.mode) above are all the contents of the article "sample Analysis of Image Compression in python3" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Channels pictures articles examples analysis content not much code most more knowledge industry information information channels channels references learning help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Apple Shulou Information NVidia Docker