I need to send a picture to another place, where it requires picture size must be less than 512kb.
I use PIL
to deal with my picture which download from internet. so I don't know what will be the next picture's size, code like this:
from PIL import Image
picture_location = '/var/picture/1233123.jpg'
compressed_picture_location = '/var/picture/1233123_compressed.jpg'
im = Image.open(picture_location)
quality = 75
im.save(compressed_picture_location, quality=quality)
im.save()
The problem is that the compressed picture's file size is not 75% or 75%*75% of the origin picture, so I have to compress it, stat it, compressed again, I can't select a suitable quality value.
Is there other way to solve this problem? Please help or try to give some ideas how to achieve this.