我用PIL打开了一张照片,但是当我试图split()分割频道时,我得到了以下错误:
AttributeError: 'NoneType' object has no attribute 'bands'
import Image
img = Image.open('IMG_0007.jpg')
img.split()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/home/blum/<ipython console> in <module>()
/usr/lib/python2.6/dist-packages/PIL/Image.pyc in split(self)
1495 "Split image into bands"
1496
-> 1497 if self.im.bands == 1:
1498 ims = [self.copy()]
1499 else:
AttributeError: 'NoneType' object has no attribute 'bands'
Run Code Online (Sandbox Code Playgroud) 我有一个 dockerized django 应用程序,我想投入生产。但是自从我添加了一个 Imagefield Pillow 之后,我就很难在 Docker 容器中安装 Pillow。
据我了解,添加依赖项 jpeg-dev ibjpeg & zlib-dev 应该足以用于 django (?)。使用下面的配置我收到错误:
错误runserver:
product.Product.image: (fields.E210) Cannot use ImageField because Pillow is not installed.
HINT: Get Pillow at https://pypi.org/project/Pillow/ or run command "pip install Pillow".
product.Product.thumbnail: (fields.E210) Cannot use ImageField because Pillow is not installed.
HINT: Get Pillow at https://pypi.org/project/Pillow/ or run command "pip install Pillow".
Run Code Online (Sandbox Code Playgroud)
如果我将 Pillow 添加到 requirements.txt(或放入pip install PillowDockerfile),我会在尝试构建容器时收到更长的错误消息。
不放入pip install PillowDockerfile 或 requirements.txt - 这是我的配置。 …
我正在尝试使用 python 将 HEIC 转换为 JPG。关于这个主题的唯一其他答案使用了 pyheif。我在 Windows 上,pyheif 不支持 Windows。有什么建议么?我目前正在尝试使用枕头。
我需要将一些网站的图像存储推送到可以无限扩展的服务(S3,CloudFiles等).到目前为止,我们已经能够允许我们的用户使用Python的成像库动态生成自定义缩略图大小,并在Django中提供sorl-thumbnail的帮助.
通过将我们的图像移动到像S3这样的东西,快速创建动态缩略图的能力就会丢失.我们可以:
此时#3看起来是一个解决问题的简单方法,但缺点很少.来自该网站的一些快速测试和数据表明,质量没有预期的那么糟糕(我们可以确保保持纵横比).
关于我们可能没有考虑的其他选择或缺点的任何建议?
注意:图像是数码照片,仅用于在网络上显示.尺寸范围从1000到50像素的高度/宽度.
browser image-processing amazon-s3 cloudfiles python-imaging-library
我使用PIL定期打开NOAA的AREA文件.在我收到的最后一批图像中,image.open()命令根本不起作用.这是我写的一个简单的代码,它产生相同的结果.它将使用一个月前的文件打开,旋转和执行正常任务,而不是使用今天的文件.
from PIL import Image
im = Image.open("path/to/file")
im.show()
Run Code Online (Sandbox Code Playgroud)
这是错误:
File "image_goes.py", line 2, in <module>
im = Image.open("path/to/file")
File "/usr/lib/python2.6/dist-packages/PIL/Image.py", line 1980, in open
raise IOError("cannot identify image file")
IOError: cannot identify image file
Run Code Online (Sandbox Code Playgroud)
这是我尝试过的:
我的假设是我们的下载脚本存在问题并且它没有完全下载文件,但是这个假设被新文件大小正确并且我使用FTP客户端手动下载它们而被拒绝了相同的结果.
我唯一的另一个理论是今天的NOAA文件存在问题,或者它们已被改变,以致PIL无法再处理它们,但我发现这不太可能.
任何帮助非常感谢,谢谢
给定django图像字段,如何创建PIL图像,反之亦然?
简单的问题,但很难谷歌:(
(我将使用django-imagekit的处理器来旋转已经存储为模型属性的图像.)
编辑
In [41]: m.image_1.__class__
Out[41]: django.db.models.fields.files.ImageFieldFile
In [42]: f = StringIO(m.image_1.read())
In [43]: Image.open(f)
---------------------------------------------------------------------------
IOError Traceback (most recent call last)
<ipython-input-43-39949b3b74b3> in <module>()
----> 1 Image.open(f)
/home/eugenekim/virtualenvs/zibann/local/lib/python2.7/site-packages/PIL/Image.pyc in open(fp, mode)
2023 pass
2024
-> 2025 raise IOError("cannot identify image file")
2026
2027 #
IOError: cannot identify image file
In [44]:
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Python在图像上绘制一个圆圈.我尝试使用PIL,但我想指定一个linewidth.目前,PIL绘制一个圆圈,但边界太薄.
这就是我所做的.
对于测试图像:我在MS Paint中创建了一个1632 X 1200图像并将其填充为绿色.我叫它test_1.jpg.这是输入文件:

from PIL import Image, ImageDraw
im = Image.open('test_1.jpg')
width, height = im.size
eX, eY = 816,816 #Size of Bounding Box for ellipse
bbox = (width/2 - eX/2, height/2 - eY/2, width/2 + eX/2, height/2 + eY/2)
draw = ImageDraw.Draw(im)
bbox_L = []
for j in range(0,5):
bbox_L.append([element+j for element in bbox])
draw.ellipse(tuple(bbox_L[j]), outline ='white')
im.show()
Run Code Online (Sandbox Code Playgroud)
基本上,我试图绘制多个圆圈,这些圆圈将在同一个点上居中但具有不同的半径.我的想法是,这会产生更粗的线条效果.
问题:正如您所看到的,左下角和右上角太薄了.此外,各个圆圈之间也存在间隙(参见左上角和右下角).
圆圈的厚度各不相同.我正在寻找一个厚度均匀的圆圈.
问题: 有没有办法在Python上绘制一个圆圈,在像test_1.jpg这样的图像上,使用PIL,NumPy等来指定线条厚度?
我正在编写一个从图形(JPEG)中获取绘图数据的程序.垂直轴是对数的.我成功地制作了一个程序,将水平和垂直轴理解为线性(不是对数),请参阅下面的代码:

%matplotlib inline
from PIL import Image
from scipy import *
from pylab import *
im = array(Image.open('fig1.jpg'))
hh = im.shape[0]
ww = im.shape[2]
imshow(im)
print(im[100,0,:])
Col = array([255,0,0])#?
bnd = 30
yax = linspace(0.5,2e-4,hh)
xax = linspace(1,14,ww)
for i in range(hh):
for j in range(ww):
im[i,j,:] = 255*(any(im[i,j,:]>Col+bnd) or any(im[i,j,:]<Col-bnd))
mapim = abs(im[:,:,0]/255-1).astype(bool)
yval = array([average(yax[mapim[:,t]]) for t in range(ww)])
rlt = interp(range(100),xax,yval)
Run Code Online (Sandbox Code Playgroud)
我不知道如何修改它以使其理解对数轴.请帮我.
python matplotlib scipy python-imaging-library jupyter-notebook
我试图从与我的python脚本所在的文件夹相同的文件夹中加载图像.
# create a class called Person
# create init method
# 2 attributes (name, and birthdate)
# create an object from the Person class
from PIL import Image, ImageTK
import datetime
import tkinter as tk
# create frame
window = tk.Tk()
# create frame geometry
window.geometry("400x400")
# set title of frame
window.title("Age Calculator App")
# adding labels
name_label = tk.Label(text="Name")
name_label.grid(column=0, row=0)
year_label = tk.Label(text="Year")
year_label.grid(column = 0, row = 1)
month_label = tk.Label(text="Month")
month_label.grid(column = 0, row = …Run Code Online (Sandbox Code Playgroud) 背景
在过去的几天里,我一直在努力部署使用Pillow的Lambda,而我正在使用Python 3.6进行部署.值得注意的是,我正在Windows 10环境中开发它.
第一次尝试
我开始通过执行以下操作将pip安装在我的工作区中严格安装:
pip3 install pillow -t "D:\Work and Projects\...\...\<projectdir>\pillow"
Run Code Online (Sandbox Code Playgroud)
我有其他软件包,并尝试在同一庄园中安装软件包,其中一个特别是praw,我这样做:
pip3 install praw -t "D:\Work and Projects\...\...\<projectdir>\praw"
Run Code Online (Sandbox Code Playgroud)
在将我的项目内容压缩到一起之后,我将我的包上传到Lambda并在第一次测试时收到错误:
无法导入模块'motw_lambda':无法导入名称'_imaging'
然后,我移除了Pillow包,试图查看这个问题源于哪里(Pillow或praw或其他一个包).删除Pillow后,执行成功.然后我在pillow包中删除了包并尝试:
pip3 install pillow -t "D:\Work and Projects\...\...\<projectdir>\PIL"
Run Code Online (Sandbox Code Playgroud)
和
pip3 install pillow -t "D:\Work and Projects\...\...\<projectdir>\Pillow"
Run Code Online (Sandbox Code Playgroud)
但是与包有同样的错误'_imaging'.
进一步尝试
然后我按照这个资源的指示和这个.我也尝试过使用virualenv甚至是lambda-uploader.
奇怪的是,我得到了同样的错误!我在这里都没有选择,感觉我正在做一些愚蠢的事情,或者目前在Lambda-Python3.6上这是不可能的(虽然我无法想象其他人没有在py3.6-中使用过枕头lambda还......)
任何信息,帮助或通用资源将不胜感激!
python ×7
django ×2
pillow ×2
amazon-s3 ×1
aws-lambda ×1
browser ×1
cloudfiles ×1
docker ×1
heic ×1
image ×1
imagefield ×1
jpeg ×1
matplotlib ×1
noaa ×1
python-2.7 ×1
scipy ×1
tkinter ×1