So I looked at this question and got the following code from it:
import Image, ImageFile
pic = pic/goes/here.jpg
im = Image.open(pic)
width, height = im.size
if width > 1000 or height > 1000:
width = width*.7
height = height*.7
im = im.resize((int(math.floor(width)), int(math.floor(height))), Image.ANTIALIAS)
try:
im.save(pic,optimize=True,quality=80)
except IOError:
ImageFile.MAXBLOCK = width * height
im.save(pic,optimize=True,quality=80)
The last bit at the end came from this question as I noticed PIL just kind of gave up when the file exceeded around 1500~ px in size (I have no clue why?)
The problem is that when I run this code with a roughly 2500x1600 image PIL either gives me an image thats the same size (1.2MB) or an empty file with 0 MB. I once even got a file that was bigger!?!? (1.38MB)
So what am I doing wrong? I just want to optimize the image to as small of a file size without losing about 80% quality.
Also any other ways to reduce the file size in python? Thanks!!