通过PIL(与此问题相关),我在哪里可以获得全面的图像模式列表?我看到"RGB","RGBX",我的代码以某种方式具有"BGRX",即使它在我可以看到的PIL文档中没有提到.例如,如何查看与Windows API调用交互时哪个,PIL支持哪些以及选择哪种正确模式?
基本上我对图像模式知之甚少,并且想要学习的不仅仅是用什么字母来使它神奇地起作用.
有没有办法导入目录中的所有图像(目录位置已知).
如果有帮助,我已经找到了找出目录长度的方法.
我不确定的是如何将图像(使用PIL/Pillow)导入列表或字典中.
我已经开始使用Python中的图像了,我想开始使用PIL(Pillow).为了安装它,我跑了pip install Pillow.安装时,之前未安装PIL.我也试过卸载它并重新安装它,以及使用它pip3 install Pillow.
当我在Python中运行它时,我的第一行是:
File "C:\Program Files\Python36\lib\site-packages\PIL\Image.py", line 56, in <module>
from . import _imaging as core
ImportError: DLL load failed: The specified procedure could not be found.
Run Code Online (Sandbox Code Playgroud)
我检查了目录,文件_imaging.cp36-win_amd64.pyd存在于PIL文件夹下.
如果需要的DLL存在,为什么会发生这种情况?我该如何解决?
假设我的图像是2322像素x 4128像素.如何缩放它以使宽度和高度都小于1028px?
我将无法使用Image.resize(https://pillow.readthedocs.io/en/latest/reference/Image.html#PIL.Image.Image.resize)因为这需要我给出新的宽度和高度.我打算做的是(下面的伪代码):
if (image.width or image.height) > 1028:
if image.width > image.height:
tn_image = image.scale(make width of image 1028)
# since the height is less than the width and I am scaling the image
# and making the width less than 1028px, the height will surely be
# less than 1028px
else: #image's height is greater than it's width
tn_image = image.scale(make height of image 1028)
Run Code Online (Sandbox Code Playgroud)
我猜我需要使用Image.thumbnail,但根据这个例子(http://pillow.readthedocs.org/en/latest/reference/Image.html#create-thumbnails)和这个答案(如何使用PIL调整图像大小并保持其宽高比?),提供宽度和高度以创建缩略图.是否有任何功能可以采用新的宽度或新的高度(不是两者)并缩放整个图像?
我有一个导入Pillow库的python文件.我可以打开图像
Image.open(test.png)
Run Code Online (Sandbox Code Playgroud)
但是如何关闭该图像呢?我没有使用Pillow来编辑图像,只是为了显示图像并允许用户选择保存或删除它.
我尝试运行的单行如下:
from PIL import Image
Run Code Online (Sandbox Code Playgroud)
无论看起来多么简单,它都会出错:
Traceback (most recent call last):
File "C:\...\2014-10-22_12-49.py", line 1, in <module>
from PIL import Image
File "C:\pyzo2014a\lib\site-packages\PIL\Image.py", line 29, in <module>
from PIL import VERSION, PILLOW_VERSION, _plugins
ImportError: cannot import name 'VERSION'
Run Code Online (Sandbox Code Playgroud)
如果这是有帮助的,我安装了枕头https://pypi.python.org/pypi/Pillow/2.6.1(文件Pillow-2.6.1.win-amd64-py3.4.exe运行此之前)(在此之前,已经有索姆PIL安装,这是我卸载).该脚本使用Python 3.4.1版在Pyzo中运行.
出了什么问题,我该怎么导入Image?
python python-import importerror python-imaging-library pillow
我想在pillow-python中调整图像大小,但是我有两个选择使用的函数:
Image.resize http://pillow.readthedocs.org/en/latest/reference/Image.html#PIL.Image.Image.resize
和
Image.thumbnail
http://pillow.readthedocs.org/en/latest/reference/Image.html#PIL.Image.Image.thumbnail
这两个定义都指出要调整图像的大小,我应该使用哪一个?
我正在尝试在基于python:alpine的Docker容器中运行Python的Scrapy .它以前工作过,但现在我想使用Scrapy的Image Pipeline,它需要我安装Pillow.
作为简化示例,我尝试了以下方法Dockerfile:
FROM python:alpine
RUN apk --update add libxml2-dev libxslt-dev libffi-dev gcc musl-dev libgcc openssl-dev curl
RUN apk add libjpeg zlib tiff freetype lcms libwebp tcl openjpeg
RUN pip install Pillow
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试构建它时,我得到一个错误,其中包含以下内容:
Traceback (most recent call last):
File "/tmp/pip-build-ft5yzzuv/Pillow/setup.py", line 744, in <module>
zip_safe=not debug_build(), )
File "/usr/local/lib/python3.6/distutils/core.py", line 148, in setup
dist.run_commands()
File "/usr/local/lib/python3.6/distutils/dist.py", line 955, in run_commands
self.run_command(cmd)
File "/usr/local/lib/python3.6/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/usr/local/lib/python3.6/site-packages/setuptools/command/install.py", line 61, in …Run Code Online (Sandbox Code Playgroud) 我安装了Python Pillow,我正在尝试裁剪图像.
其他效果很好(例如,缩略图,模糊图像等)
每当我运行下面的代码时,我都会收到错误消息:
瓷砖不能延伸到图像外
test_image = test_media.file
original = Image.open(test_image)
width, height = original.size # Get dimensions
left = width/2
top = height/2
right = width/2
bottom = height/2
cropped_example = original.crop((left, top, right, bottom))
cropped_example.show()
Run Code Online (Sandbox Code Playgroud)
我使用了我为PIL找到的裁剪示例,因为我找不到枕头(我假设它是相同的).
我正在使用Pillow和numpy,但在Pillow Image对象和numpy数组之间进行转换时遇到问题.
当我执行以下代码时,结果很奇怪.
im = Image.open(os.path.join(self.img_path, ifname))
print im.size
in_data = np.asarray(im, dtype=np.uint8)
print in_data.shape
Run Code Online (Sandbox Code Playgroud)
结果是
(1024, 768)
(768, 1024)
Run Code Online (Sandbox Code Playgroud)
尺寸为何改变?
pillow ×10
python ×8
alpine-linux ×1
arrays ×1
colors ×1
docker ×1
dockerfile ×1
image ×1
importerror ×1
numpy ×1