Because some compression technologies are required to build my photography website to speed up Website access.
So I learned how to compress images in a python environment.
1. Download and install PIL
After you download and install the package, django reports an error saying that the PIL package has an error.
Then, I google the error and found django on this page, saying that PIL cannot be used and pillow must be used.
So I have to uninstall PIL again.
When I used pip and uninstall pil, I found that my pip version was too low and needed to be upgraded. Finally, I used easy_install to upgrade pip.
Reinstall pillow. You 'd better uninstall the earlier version of pillow and then install it again.
Recovery completed .... Too pitfall...
2. When PIL is used, the IOError: decoder jpeg not available error occurs.
Solution:
install libpng and libjpeg package (combo installer) from this link: http://ethan.tira-thompson.com/Mac_OS_X_Ports.html
sudo pip install -I pillow
3. Use PIL to compress the image and reference it from the http://fc-lamp.blog.163.com/blog/static/174566687201282424018946/
# Coding: UTF-8 ''' python Image processing @ author: fc_lamp @ blog: http://fc-lamp.blog.163.com/'''from PIL import image as Image # proportional Compression image def resizeImg (** args ): args_key = {'ori _ img ': '', 'dst _ img':'', 'dst _ W': '', 'dst _ H ':'', 'Save _ Q': 75} arg = {} for key in args_key: if key in args: arg [key] = args [key] im = image. open (arg ['ori _ img ']) ori_w, ori_h = im. size widthRatio = heightRatio = None ratio = 1 if (ori_w and ori_w> arg ['dst _ W']) or (ori_h and ori_h> arg ['dst _ H']): if arg ['dst _ W'] and ori_w> arg ['dst _ W']: widthRatio = float (arg ['dst _ W']) /ori_w # correct way to obtain decimals if arg ['dst _ H'] and ori_h> arg ['dst _ H']: rows = float (arg ['dst _ H'])/ori_h if widthRatio and heightRatio: if widthRatio