Home > Article > Backend Development > How to install python's pil library
PIL: Python Imaging Library is already the de facto image processing standard library for the Python platform. PIL is very powerful, but the API is very simple and easy to use.
Install PIL(Recommended learning: Python video tutorial)
Directly under Debian/Ubuntu Linux Install through apt:
$ sudo apt-get install python-imaging
Mac and other versions of Linux can be installed directly using easy_install or pip. Before installation, you need to install the compilation environment:
$ sudo easy_install PIL
If the installation fails, follow the prompts to remove the missing files first. package (such as openjpeg) installed.
For Windows platform, go to the PIL official website to download the exe installation package.
Operation images
Let’s take a look at the most common image scaling operations, which only require three or four lines of code:
import Image # 打开一个jpg图像文件,注意路径要改成你自己的: im = Image.open('/Users/michael/test.jpg') # 获得图像尺寸: w, h = im.size # 缩放到50%: im.thumbnail((w//2, h//2)) # 把缩放后的图像用jpeg格式保存: im.save('/Users/michael/thumbnail.jpg', 'jpeg')
Other functions such as slicing and rotation , filters, output text, color palette, etc. are all available.
For more Python related technical articles, please visit the Python Tutorial column to learn!
The above is the detailed content of How to install python's pil library. For more information, please follow other related articles on the PHP Chinese website!