"Python Notes" image processing library PIL source installation steps

Source: Internet
Author: User
Tags image processing library

The previous time item needs to have some pictures to draw water to print, uses the Python PIL library, this article takes the Imaging-1.1.7 as an example, records the PIL library The source code compiles/installs the procedure.

PIL full name Python image Library, it supports a variety of image format processing, to our application proxy powerful image processing capabilities, such as cutting, rotating, water printing and so on.

Download from the official website v1.1.7 version source and decompression, CD to unzip the directory, read the readme, if you want to process JPEG images in the application, you need to pre-install JPEG library, otherwise use will error .

1. Compiling and installing the JPEG library
1.1 Compiling the source code

Download stable version of JPEG source from the JPEG library website (the latest stable version is v9a), unzip the source of GZ package, CD to extract directory, vi open makefile file, modify 2:
1) Set the prefix variable to the installation target path of the JPEG library
2) Append the-fpic parameter to the Cflags setting (for the role of PIC, which can be understood by man GCC or see here)
Note: since the installation of Imaging later, you need to compile a _imaging.so library file, it is necessary to set the-fpic parameter, otherwise Imaging compile will report the following error (if you want to verify, you can try-_-):

/USR/BIN/LD:/home/slvher/python-2.7.5/3rd-lib-src/jpeg-6b/lib/libjpeg.a (JCPARAM.O): Relocation R_X86_64_32 Against ' a local symbol ' can not is used when making a shared object; Recompile with-fpic/home/slvher/python-2.7.5/3rd-lib-src/jpeg-6b/lib/libjpeg.a:could not read Symbols:bad Valuecollect2:ld returned 1 exit Statuserror:command ' gcc ' failed with exit status 1
1.2 Install-lib
After compiling the JPEG source code with the-fpic parameter, execute the following command:
Make Installmake Install-lib
The above command to "install" the compiled JPEG library to the path specified by prefix (in fact, from the source directory CP file to the prefix directory)

2. Installing the Imaging Library
CD to Imaging-1.1.7,vi open setup.py, modify the file:
1) Comment out jpeg_root = None
2) Add jpeg_root = Libinclude ("/home/slvher/python-2.7.5/3rd-lib-src/jpeg-6b"), Save the Exit and execute the following command:
Python setup.py build_ext-i
Under normal circumstances, imaging Library compilation will succeed
You can then install the PIL library into the Python site-packages directory by executing the following command:
Python setup.py Install

After that, the application can use the Gil Library as usual.

Resources
1. PIL Official website
2. PiL Source Code Readme Document

"Python Notes" image processing library PIL source installation steps

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.