问题标签 [python-imaging-library]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
4 回答
1572 浏览

jquery - 使用 PiL 截取 HTML/CSS

我想让网站上的用户上传图片,并在上面写一些文字。此外,他们应该能够裁剪/缩放/移动图像和文本。对于那些东西,我可以在 jQuery 中完成。

在他们按照他们想要的方式制作图像之后,有没有办法我可以截取该图像的屏幕截图(使用 PiL)并将其保存在服务器上?

最好/正确的方法是什么?

0 投票
3 回答
4718 浏览

python - 如何检查 RGB 图像是否只包含一种颜色?

我正在使用 Python 和 PIL。

我有 RGB 图像,我想知道那些只包含一种颜色(例如 #FF0000)或一些非常接近的颜色(#FF0000 和 #FF0001)的图像。

我正在考虑使用直方图,但很难用 3 个色带找出一些东西,所以我正在寻找一种更聪明的算法。

有任何想法吗?

ImageStat 模块就是答案!谢谢亚伦。我使用 ImageStat.var 来获取方差,并且效果很好。

这是我的一段代码:

0 投票
2 回答
2349 浏览

python - 为 JPEG 构建 Python PIL 看起来不错,但自检失败

我在 Fedora Core 6(64 位)上

在“yum install libjpeg-devel”之后,我已经下载并构建了 PIL。它给出了以下信息:

--- JPEG 支持正常

看起来 JPEG 构建得很好,但是在运行 selftest.py 时:

IOError:解码器 jpeg 不可用

为什么它看起来构建正确,但自检失败?

0 投票
4 回答
1608 浏览

image - 这种裁剪算法的更优雅的改写是什么?(在 Python 中)

我想在我的 Django 应用程序中裁剪缩略图图像,以便获得显示图像中心的二次图像。这不是很难,我同意。

我已经写了一些代码来做到这一点,但不知何故它缺乏某种……优雅。我不想玩代码高尔夫,但我认为必须有一种方法来表达这种更短、更 Python 的方式。

你有什么想法吗?

编辑:解释 x, y

0 投票
6 回答
13587 浏览

python - 为基本图像文件 I/O 和 Python 处理寻找 PIL 的更好替代方案?

对于基本图像文件 I/O 和 Python 中的处理, PIL( Python 成像库)是否有更好的替代品?

0 投票
2 回答
2834 浏览

python - 使用 PIL 在 Python 中将带有回车符的文本写入图像

我有一个 python 脚本,它使用 PIL 将文本写入图像。除了遇到带有回车符的字符串外,这一切都很好。我需要在文本中保留回车。我没有在图像上写回车,而是在应该返回的地方得到一个小方框字符。这是编写文本的代码:

attText 是我遇到问题的变量。我在写它之前将它转换为一个字符串,因为在某些情况下它是一个数字。

谢谢你的帮助。

0 投票
10 回答
116040 浏览

python - 如何使用 PIL 使所有白色像素透明?

我正在尝试使用 Python 图像库使所有白色像素透明。(我是一个试图学习 python 的 C 黑客,所以要温柔)我已经进行了转换(至少像素值看起来正确)但我不知道如何将列表转换为缓冲区以重新创建图片。这是代码

0 投票
1 回答
1300 浏览

python - Converting an ImageMagick FX operator to pure Python code with PIL

I'm trying to port some image processing functionality from an Image Magick command (using the Fx Special Effects Image Operator) to Python using PIL. My issue is that I'm not entirely understanding what this fx operator is doing:

From a high level, this command takes the colors from a gradient image (gradient.png) and applies them as the color palette of the input image (input.png), writing to an output image (output.png).

From what I've figured out, u is the input image, v is the gradient, and it is going through each left-most pixel in the gradient from top to bottom, somehow applying its colors to the input image.

I can't wrap my head around how to do this same thing programmatically with PIL. The best thing I've come up with was to convert the image to a paletted image (down-sampling to a measly 256 colors) and grabbing colors individually from the gradient with a pixel access object.

This works, but like I said, it down-samples to 256 colors. Not only is this a ham-handed way of doing things, it results in a really crappy output image. How could I duplicate the Magick functionality without cramming the result into 265 colors?

addendum: forgot to cite the blog where I found the original Magick command

0 投票
1 回答
693 浏览

image - 如何将 Pyglet 图像的区域放入 PIL 图像中?

我的应用程序从视频中读取帧(使用 pyglet),提取“条带”(即区域 - 全宽 1 到 6 条视频线),然后将每个条带(附加它)粘贴到稍后可以写出 *. .png 文件。

问题是 Pyglet GL 图像存储在图形内存中,因此 re 大小非常有限。我目前的笨拙解决方法是将要成为的 png 图像构建为小图块(即在 pyglet GL 大小限制内),当图块已满时,将其写入 *png 文件,将其作为 PIL 图像文件读回,然后将平铺图像粘贴/附加到最终的 PIL Image * png 文件中。

我认为应该可以将 pyglet-GL 条转换为 PIL 图像友好格式,并将其直接粘贴/附加到最终的 PIL 图像中,因此不需要瓷砖业务,这会使事情变得非常复杂并具有性能影响.

但是我找不到如何将条形数据转换为可以粘贴到 PIL 图像中的表单。已经看到许多请求重新转换为另一种方式,但我从未与牛群一起奔跑。

0 投票
3 回答
2334 浏览

python - 为什么 Tkinter 使用 canvas.create_image 中断?

我有一个正在运行的 python GUI 应用程序,我打算在 Windows 和 Mac 上使用它。Tkinter 上的文档不是最好的,而且 google-fu 让我失望了。

简而言之,我正在做:

如果我注释掉 create_bitmap 行,应用程序绘制得很好。如果我重新评论它,我会收到以下错误:

_tkinter.TclError: unknown option "-image"

这很奇怪。根据python 测试(即导入_tkinter、Tkinter 和doing Tk()),Tkinter 很好。我已经在我的 Windows 设置(XP SP3,Python 2.6)上安装了 PIL,想象它正在做一些低级别的繁重工作。似乎不是;我仍然收到上述错误。

完整的堆栈跟踪,不包括我已经粘贴的代码,是:

任何人都能够阐明任何启示?