简体   繁体   中英

Compressing PIL image without saving the file

I am having trouble with compressing image in python without saving the image at the disk. The image has a save function as described here . Here it optimizes the image by saving it. Is it possible to use the same procedure without saving the image. I want to do it like another python function.

image=image.quantize() [here it reduces the quality a lot ]

Thanks in advance:)

In PIL or opencv the image is just a large matrix with values for its pixels. If you want to do something with the image(eg display it), the function needs to know all the pixel values, and thus needs the extracted image.

However, there is a method to keep the image compressed in memory until you really need to do something with the image. Have a look at this answer: How can i load a image in Python, but keep it compressed?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM