Я установил PIL 1.1.7 из источника на Mac OSX.Я также установил необходимые библиотеки из Macports.Использование python 2.6.
После установки PIL я мог успешно запустить selftest.py (все тесты проходят)
Но когда я пытаюсь запустить следующий код, я обнаружил, что не могуконвертировать PNG в JPG.Однако я могу конвертировать PNG в GIF, PNG в PPM.Я также могу читать JPG.
import os
import sys
import Image
for infile in sys.argv[1:]:
f, e = os.path.splitext(infile)
outfile = f + ".jpg"
print outfile
if infile != outfile:
try:
Image.open(infile).save(outfile, 'jpg') #Note: gif or ppm works
except IOError:
print "cannot convert", infile
if os.path.exists(outfile):
print 'cleaning up...'
os.remove(outfile)
** обновление с трассировкой стека.Похоже, кодер отсутствует.Однако я установил libjpeg через macport.
Очистка ...
Traceback (most recent call last):
File "convert_to_jpeg.py", line 15, in <module>
Image.open(infile).save(outfile, 'jpeg')
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PIL/Image.py", line 1439, in save
save_handler(self, fp, filename)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PIL/JpegImagePlugin.py", line 471, in _save
ImageFile._save(im, fp, [("jpeg", (0,0)+im.size, 0, rawmode)])
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PIL/ImageFile.py", line 495, in _save
e = Image._getencoder(im.mode, e, a, im.encoderconfig)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PIL/Image.py", line 401, in _getencoder
raise IOError("encoder %s not available" % encoder_name)
IOError: encoder jpeg not available