"Python Notes" image processing library PIL source code installation steps

Source: Internet
Author: User
Tags image processing library

The previous time item needs to have some picture to draw water to print, uses the Python PIL library, this article takes Imaging-1.1.7 as an example, records the source code compilation/Installation step of the PIL library.

PIL full name Python Image Library. It supports the processing of a variety of image formats, enabling our applications to proxy powerful image processing capabilities such as cropping, rotating, water-stamping, etc.

Download the v1.1.7 version number from the official website source code and unzip, CD to unzip the folder, read the README. If you want to work with JPEG pictures in your app. The JPEG library needs to be pre-installed. Otherwise, the error will be used .

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

Download the JPEG source code for the stable version number from the JPEG library website (the latest stable version is v9a) and unpack the source code GZ package. CD to unzip folder, VI to open the makefile file. Changes in 2 places:
1) Set the prefix variable to the installation target path of the JPEG library
2) Append-fpic to the Cflags setting (for the role of PIC, you can learn or see it through man gcc)
Note: since the installation of Imaging, you need to compile a _imaging.so library file, it is necessary to set-fpic parameters, otherwise Imaging compile will be reported such as 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-FPIC parameters. Run such as the following command:
Make Installmake Install-lib
The above command installs the compiled JPEG library to the path specified by prefix (in fact from the source code folder CP file to the prefix folder)

2. Installing the Imaging Library
CD to Imaging-1.1.7,vi open setup.py. Change file:
1) stare out jpeg_root = None
2) Add jpeg_root = Libinclude ("/home/slvher/python-2.7.5/3rd-lib-src/jpeg-6b"), Save exit and run for example 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 folder by running the following command, for example:
Python setup.py Install

After that, the application will be able to use the Gil library properly.

"References"
1. PIL Official website
2. PiL Source Code Readme Document

"Python Notes" image processing library PIL source code 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.