|
In the Python runtime environment for the server to get such a mistake about the image processing program Times today:
NameError: global name 'Image' is not defined
import Image next, found that Python does not own image processing library, requires a separate installation ...... next check, Python commonly used image processing library called PIL, you can use pip install - so good in the first types pip install with virtualenv PIL.
Installation completed soon, so pleasant to refresh, waiting through the program, the results being given:
IOError: decoder jpeg not available
Under Google, and we found that by pip install PIL is not installed jpeg decoder ...... examination under the installation log, also has such a description:
-------------------------------------------------- ------------------
PIL 1.1.7 SETUP SUMMARY
-------------------------------------------------- ------------------
version 1.1.7
platform linux2 2.7.5 (default, Sep 18 2013, 09:53:07)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)]
-------------------------------------------------- ------------------
*** TKINTER support not available
*** JPEG support not available
*** ZLIB (PNG / ZIP) support not available
*** FREETYPE2 support not available
*** LITTLECMS support not available
-------------------------------------------------- ------------------
To add a missing option, make sure you have the required
library, and set the corresponding ROOT variable in the
setup.py script.
JPEG support not available ...... jpg is not supported, this is the trouble Which will lead ......
So I had to manually install:
wget http://effbot.org/downloads/Imaging-1.1.7.tar.gz
tar xvfz Imaging-1.1.7.tar.gz
After you download and unzip success, to extract the directory, find Imaging-1.1.7 / setup.py file, modify the following lines of code (default TCL_ROOT set to NONE, here to spread the system library path to the job):
TCL_ROOT = "/ usr / lib64 /"
JPEG_ROOT = "/ usr / lib64 /"
ZLIB_ROOT = "/ usr / lib64 /"
TIFF_ROOT = "/ usr / lib64 /"
FREETYPE_ROOT = "/ usr / lib64 /"
LCMS_ROOT = "/ usr / lib64 /"
Then check before installation:
python /root/nowamagic_venv/Imaging-1.1.7/setup.py build_ext -i
Check No problem, you can perform the installation:
python /root/nowamagic_venv/Imaging-1.1.7/setup.py install
Successful installation:
-------------------------------------------------- ------------------
PIL 1.1.7 SETUP SUMMARY
-------------------------------------------------- ------------------
version 1.1.7
platform linux2 2.7.5 (default, Sep 18 2013, 09:53:07)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)]
-------------------------------------------------- ------------------
*** TKINTER support not available
--- JPEG support available
--- ZLIB (PNG / ZIP) support available
--- FREETYPE2 support available
*** LITTLECMS support not available
-------------------------------------------------- ------------------
Jpg has now been supported, the program is successful, briefly record what process to facilitate newcomers. Incidentally, with a test program, using Tornado upload photos and generate thumbnails:
import time
import tempfile
import Image
class AsciiImageProcessHandler (tornado.web.RequestHandler):
def post (self):
if self.request.files:
for f in self.request.files [ 'image']:
rawname = f [ 'filename']
dstname = str (int (time.time ())) + '.' + rawname.split ( '.'). pop ()
thbname = "thumb _" + dstname
self.write (dstname)
tf = tempfile.NamedTemporaryFile ()
tf.write (f [ 'body'])
tf.seek (0)
# Create normal file
# Img = Image.open (src)
img = Image.open (tf.name)
img.thumbnail ((920,920), resample = 1)
img.save ( "./ static / upload / asciiimg /" + dstname)
# Create thumb file
img.thumbnail ((100,100), resample = 1)
img.save ( "./ static / upload / asciiimg_tn /" + thbname)
tf.close () |
|
|
|