在VIEW中,我想调整上传图像的大小,并在模型中保存2份副本并进行更改
编辑: 实际上,我需要一种方法,我可以读取线条,并将像素信息提取到一些结构,所以我可以使用putpixel函数创建基于ppm p3文件的图像.
我已经尝试了这么久,我不能只是做对了.
我正在使用Python Imaging Library(PIL),我想打开一个PPM图像并将其显示为屏幕上的图像.
我怎么能只使用PIL呢?
这是我的ppm图片.它只是我创建的7x1图像.
P3
# size 7x1
7 1
255
0
0
0
201
24
24
24
201
45
24
54
201
201
24
182
24
201
178
104
59
14
Run Code Online (Sandbox Code Playgroud) 我用PIL加载和保存图像就好了,但我似乎无法改变给定图像的"整体"色调〜谷歌和这里显示了一个答案,有点,与numpy模块,但那不是一个选项为了我
应该很简单,给定带有alpha的灰色图像,我想让它变成红色
我正在尝试与linux x屏幕截图图像进行图像比较
我遵循python脚本
http://aatiis.me/2010/08/12/fast-image-comparison-with-python.html
它可以工作并为样本鸭图像提供输出(snap_from_x_duck
AND resized_from_duck
)我用于测试,但当我加载我的实际图像(snap_from_x.png
AND resized_from_org.png
)它给出了一个错误..
Comparing 1 images:
* 1 / 1: /opt/ad_re.png /opt/op.png ...
Traceback (most recent call last):
File "imgcmp.py", line 246, in <module>
sim = cmp.similarity()
File "imgcmp.py", line 212, in similarity
cmp = self.compare()
File "imgcmp.py", line 180, in compare
diff.append(cmp.levenshtein)
File "imgcmp.py", line 127, in levenshtein
stra_r = ''.join((chr(x>>16) for x in self.imga_int))
File "imgcmp.py", line 50, in imga_int
self._imga_int = tuple(self._img_int(self._imga))
File "imgcmp.py", line 120, in _img_int
yield …Run Code Online (Sandbox Code Playgroud) 我创建了一个使用sorl-thumbnail来调整上传图像大小的网站.大多数图像都没有任何问题调整大小,但很少有人收到以下错误:
Caught IOError while rendering: not enough data
Request Method: GET
Request URL: http://localhost:8000/user/nash22/photographs/
Django Version: 1.3.1
Exception Type: TemplateSyntaxError
Exception Value:
Caught IOError while rendering: not enough data
Exception Location: /usr/local/lib/python2.7/site-packages/PIL/TiffImagePlugin.py in load, line 382
Python Executable: /usr/local/bin/python
Python Version: 2.7.1
Run Code Online (Sandbox Code Playgroud)
我在谷歌搜索但找不到任何相关的答案.有人可以帮我解决发生的事情以及如何解决这个问题?谢谢.
完成回溯
Traceback(最近一次调用最后一次):
文件"/lib/python2.7/django/core/handlers/base.py",第111行,get_response response = callback(request,*callback_args,**callback_kwargs)
文件"/home/swaroop/project/apps/photography/views.py",第702行,showPhoto context_instance = RequestContext(request))
文件"/lib/python2.7/django/shortcuts/ 初始化的.py",第20行,选择render_to_response中返回的HttpResponse(loader.render_to_string(*ARGS,**kwargs),**httpresponse_kwargs)
文件"/lib/python2.7/django/template/loader.py",第188行,在render_to_string中返回t.render(context_instance)
文件"/lib/python2.7/django/template/base.py",第123行,在渲染中返回self._render(context)
文件"/lib/python2.7/django/template/base.py",第117行,在_render中返回self.nodelist.render(context)
文件"/lib/python2.7/django/template/base.py",第744行,在render bits.append中(self.render_node(node,context))
文件"/lib/python2.7/django/template/base.py",第757行,在render_node中返回node.render(context)
文件"/lib/python2.7/django/template/loader_tags.py",第127行,在渲染中返回compiled_parent._render(context)
文件"/lib/python2.7/django/template/base.py",第117行,在_render中返回self.nodelist.render(context)
文件"/lib/python2.7/django/template/base.py",第744行,在render bits.append中(self.render_node(node,context))
文件"/lib/python2.7/django/template/base.py",第757行,在render_node中返回node.render(context)
文件"/lib/python2.7/django/template/loader_tags.py",第64行,在render result = block.nodelist.render(context)中
文件"/lib/python2.7/django/template/base.py",第744行,在render bits.append中(self.render_node(node,context))
文件"/lib/python2.7/django/template/base.py",第757行,在render_node中返回node.render(context)
文件"/lib/python2.7/sorl/thumbnail/templatetags/thumbnail.py",第45行,在渲染中返回self._render(context)
文件"/lib/python2.7/sorl/thumbnail/templatetags/thumbnail.py",第97行,在渲染文件,几何,**选项中
在get_thumbnail缩略图中输入文件"/lib/python2.7/sorl/thumbnail/base.py",第61行) …
我正在尝试从Python Imaging Library向Image类添加一个新方法.我想要一个名为DilateImage的新类,它与原始的Image类完全相同,除了它还包含一个dilate()函数,该函数在一个实例上执行时修改它.这是我的示例代码(不起作用):
import Image
def DilateImage(Image):
def dilate(self):
imnew = self.copy()
sourcepix = imnew.load()
destpix = self.load()
for y in range(self.size[1]):
for x in range(self.size[0]):
brightest = 255
for dy in range(-1,2):
for dx in range(-1,2):
try:
brightest = min(sourcepix[x+dx,y+dy], brightest)
except IndexError:
pass
destpix[x, y] = brightest
Run Code Online (Sandbox Code Playgroud)
当我尝试使用这个新的类类型来创建一个使用基类"open"函数的实例时,它失败了:
>>> test = DilateImage.open("test.jpg")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'function' object has no attribute 'open'
Run Code Online (Sandbox Code Playgroud) 在Django中,当我有一个ImageField并希望在模板中输出它的宽度时,我会:
{{ myimage.width }}
Run Code Online (Sandbox Code Playgroud)
如果找到图像,这很有效.但是,如果由于某种原因无法找到图像获取宽度,则页面会创建错误,并且模板将不会呈现.但是,这种行为是有道理的,我如何优雅地使其失败?意思是,如果无法找到图像并且能够继续渲染页面,我希望模板不为myimage.width输出任何内容.
这是图像看起来像: -

我希望看起来像这样.:-

请看,在图像的第二张图片按钮被拉了.我用一个软件来做这个,他们称这个选项为20分段.我不知道如何在python中做任何人都可以帮助我吗?我正在使用python 2.7,我也是python的新手,所以请用代码示例描述清楚.我已经尝试过Opencv矢量间距来做到这一点,但是所有的时间都给我错误的图像.
我想安装Pillow并在许多地方阅读,只有在删除PIL时才能使用.
在某处我安装了PIL,但我无法找到它或记住它是如何安装的.当我通过终端安装东西时,我几乎是一个ctrl + c和ctrl + v家伙,所以我想我在安装它时遇到了一些问题.
我试过了
pip uninstall PIL
easy_install uninstall PIL
brew uninstall PIL
Run Code Online (Sandbox Code Playgroud)
并且没有想法.我甚至找不到任何名为"PIL"的文件和聚光灯.
只是想找到摆脱PIL并安装Pillow的方法,这样我就可以为几百张图片添加文字了.
在El Capitan上运行python 2.7
我有少量要查询的颜色数据。它采用RGB数据列表的形式。
[(255, 255, 255), (124, 144, 231), ...]
该图像使用受限的调色板,我想通过沿色轮进行绘制来查看这些颜色是如何“分布”的。作为替代方案,我尝试了各个通道的直方图,但这并没有给我带来我感兴趣的见解。
我在Google上搜索并了解到,HSL颜色可以更准确地映射到色轮。但是,转换为HSL后,我仍然感到困惑。颜色仍然由3个数据组成:色相,饱和度和亮度。您如何将3个数据映射到2d平面上?
我在这里阅读了有关极坐标的信息:https : //www.mathsisfun.com/polar-cartesian-coordinates.html。我尝试通过将HSL数据视为极坐标来忽略亮度和绘图(色相=角度,饱和度=半径长度(按某些比例缩放))
def polar2cartesian(hsl):
color_circle_radius = 100
radius = hsl.saturation * color_circle_radius
x = radius * math.cos(math.radians(hsl.hue))
y = radius * math.sin(math.radians(hsl.hue))
return x, y
...
for hsl in colors:
x, y = polar2cartesian(hsl)
im.point(x, y, hsl.to_rgb())
Run Code Online (Sandbox Code Playgroud)
这不是正确的结果。由于它在多个地方都显示相同的红色色调,例如以下示例:
从RGB转换到色轮上某个位置的正确方法是什么?