当我们处理本地文件时,我试图做的事情相当简单,但当我试图用远程URL这样做时,问题就来了。

基本上,我试图从一个URL提取的文件创建一个PIL图像对象。当然,我总是可以只获取URL并将其存储在临时文件中,然后将其打开到一个图像对象中,但这感觉非常低效。

以下是我所拥有的:

Image.open(urlopen(url))

它抱怨seek()不可用,所以我尝试了这个:

Image.open(urlopen(url).read())

但这也不管用。是否有更好的方法来做到这一点,或者写入临时文件是做这类事情的公认方法?

PIL在我的系统中支持JPEG。

每当我做一个上传,我的代码失败:

File "PIL/Image.py", line 375, in _getdecoder
    raise IOError("decoder %s not available" % decoder_name)
IOError: decoder jpeg not available

我该如何解决这个问题?

我在shell中使用这个命令来安装PIL:

easy_install PIL

然后我运行python并键入:import PIL。但是我得到了这个错误:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
ImportError: No module named PIL

我从来没有遇到过这样的问题,你觉得呢?

我正在尝试使用命令安装PIL (Python映像库):

sudo pip install pil

但我得到了以下信息:

Downloading/unpacking PIL
  You are installing a potentially insecure and unverifiable file. Future versions of pip will default to disallowing insecure files.
  Downloading PIL-1.1.7.tar.gz (506kB): 506kB downloaded
  Running setup.py egg_info for package PIL
    WARNING: '' not a valid package name; please use only.-separated package names in setup.py
    
Installing collected packages: PIL
  Running setup.py install for PIL
    WARNING: '' not a valid package name; please use only.-separated package names in setup.py
    --- using frameworks at /System/Library/Frameworks
    building '_imaging' extension
    clang -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -IlibImaging -I/System/Library/Frameworks/Python.framework/Versions/2.7/include -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _imaging.c -o build/temp.macosx-10.8-intel-2.7/_imaging.o
    unable to execute clang: No such file or directory
    error: command 'clang' failed with exit status 1
    Complete output from command /usr/bin/python -c "import setuptools;__file__='/private/tmp/pip_build_root/PIL/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-AYrxVD-record/install-record.txt --single-version-externally-managed:
    WARNING: '' not a valid package name; please use only.-separated package names in setup.py

running install

running build

.
.
.
.

copying PIL/XVThumbImagePlugin.py -> build/lib.macosx-10.8-intel-2.7

running build_ext

--- using frameworks at /System/Library/Frameworks

building '_imaging' extension

creating build/temp.macosx-10.8-intel-2.7

creating build/temp.macosx-10.8-intel-2.7/libImaging

clang -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -IlibImaging -I/System/Library/Frameworks/Python.framework/Versions/2.7/include -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _imaging.c -o build/temp.macosx-10.8-intel-2.7/_imaging.o

unable to execute clang: No such file or directory

error: command 'clang' failed with exit status 1

----------------------------------------
Cleaning up…

你能帮我安装PIL吗?

我如何得到一个图片的大小与PIL或任何其他Python库?

我如何将PIL图像来回转换为NumPy数组,以便我可以比PIL的PixelAccess更快地进行逐像素转换?我可以通过以下方式将其转换为NumPy数组:

pic = Image.open("foo.jpg")
pix = numpy.array(pic.getdata()).reshape(pic.size[0], pic.size[1], 3)

但我如何加载它回到PIL图像后,我已经修改了数组?picture .putdata()工作不正常。

有没有我忽略的明显的方法?我只是想做个缩略图。