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 :: divide all the numbers of a list by one number python 
Python :: Minimum Number of Operations to Move All Balls to Each Box in python used in function method 
Python :: max sum slice python 5 - autopilot 
Python :: python cv2 blob detection seg fault 
Python :: python open file partially 
Python :: Arduino - Send Commands with Serial Communication with python 
Python :: what is python virtual environment 
Python :: how to add to an index in a list in python 
Python :: tweepy stream extended mode 
Python :: Get the count of each categorical value (0 and 1) in labels 
Python :: python redirect console output to devnull 
Python :: how to remove zero after decimal float python 
Python :: multiplication table for number python codewars 
Python :: python pass function as argument 
Python :: python download progress bar 
Python :: enumerate function in python for loop 
Python :: how to sort a dictionary in python without sort function 
Python :: python file io 
Python :: cls in python 
Python :: python bytes to hex 
Python :: list input python 
Python :: python set union 
Python :: write str 
Python :: django add user to group 
Python :: py convert binary to int 
Python :: car python program 
Python :: get length from variable python 
Python :: hash in python 
Python :: how to get a user input in python 
Python :: how to create models in django 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =