Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

optimize images using pillow

from PIL import Image
image = Image.open("test.jpg")
image.save("test2.jpg", quality=0, optimize=True)
Comment

Optimize images in python using pillow

>>> from PIL import Image
 # My image is a 200x374 jpeg that is 102kb large
 >>> foo = Image.open("path	oimage.jpg")
 >>> foo.size
  (200,374)
 # I downsize the image with an ANTIALIAS filter (gives the highest quality)
 >>> foo = foo.resize((160,300),Image.ANTIALIAS)
 >>> foo.save("path	osaveimage_scaled.jpg",quality=95)
 # The saved downsized image size is 24.8kb
 >>> foo.save("path	osaveimage_scaled_opt.jpg",optimize=True,quality=95)
 # The saved downsized image size is 22.9kb
Comment

PREVIOUS NEXT
Code Example
Python :: python colored text into terminal 
Python :: Add label to histogram 
Python :: python remove file with pattern 
Python :: plt python two axis 
Python :: Python create a new png file 
Python :: pandas.get_dummies 
Python :: different dataframe name with for loop 
Python :: load data python 
Python :: python mann kendall test 
Python :: Set value of dataframe using condition 
Python :: listas en python 
Python :: xlsb file in pandas 
Python :: ajouter element liste python 
Python :: leetcode matrix diagonal sum in python 
Python :: django filter multiple conditions 
Python :: flask on gevent over https 
Python :: python terminal progress bar 
Python :: tkinter simple application 
Python :: python dataframe calculate difference between columns 
Python :: pygame bg color 
Python :: ImportError: No module named _bootlocale 
Python :: split by backslash python 
Python :: fizz buzz in python 
Python :: strip characters from a string python 
Python :: kdeplot python 
Python :: beautifulsoup get h1 
Python :: python in stack 
Python :: python qr decomposition 
Python :: python queue not empty 
Python :: python area calculator 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =