Reputation: 2433
No matter what I do to reduce the quality of the PNG image, this does not chnage the file size, it appears that it is not working with me, how can I use quality argument to reduce the quality and hence the file size of the image, see my code below.
Note that the original image type is JPEG.
Changing the quality below from 100 to 0 does not do anything.
Code:
basewidth = 400
im = Image.open(path+item)
try:
for orientation in ExifTags.TAGS.keys():
if ExifTags.TAGS[orientation]=='Orientation':
break
exif=dict(im._getexif().items())
if exif[orientation] == 3:
im=im.rotate(180, expand=True)
elif exif[orientation] == 6:
im=im.rotate(270, expand=True)
elif exif[orientation] == 8:
im=im.rotate(90, expand=True)
im.save(path+item)
except:
print "exception"
pass
im = add_corners(im, 180)
f, e = os.path.splitext(path+item)
wpercent = (basewidth/float(im.size[0]))
hsize = int((float(im.size[1])*float(wpercent)))
imResize = im.resize((basewidth,hsize), Image.ANTIALIAS)
imResize.save(f + '.png', format="PNG", quality=10, optimize=True)
Upvotes: 0
Views: 2233
Reputation: 149
This resized the image to me:
img = PIL.Image.open("c:\\my_image.png")
newimg_signature = img.resize((185, 86))
Upvotes: 0
Reputation: 2433
I ended up using compress_level
imResize.save(f + '.png', format="PNG", compress_level=5)
also the following can be used optimize=True
Upvotes: 1