【问题标题】:Create, Modify, and Save an image in python 3.x在 python 3.x 中创建、修改和保存图像
【发布时间】:2016-02-02 17:27:32
【问题描述】:

我目前正在制作一个将信息呈现到缓冲区的程序,并且我想将信息作为某种图像文件保存到我的工作目录中。我看过一些使用 PIL 的示例,但是 python 3.x 不支持该库。有更好的选择吗?

【问题讨论】:

  • 尝试 PIL 的克隆,Pillow。它有一个 3.X 分支,我上次检查过。
  • 是的,凯文是对的。我在 3.x 中使用 Pillow 来满足我所有的图像处理需求
  • 奇怪,我通过 pip 安装了枕头,但我无法在 python 命令行中导入它。 pip list 显示 Pillow 已安装。

标签: python image file python-3.x save


【解决方案1】:

先卸载 PIL 再安装 Pillow

它是 PIL 的克隆,适用于 python 3.x。

from PIL import Image
img = Image.open("test1.jpg") #jpg, png, etc.
pix = img.load()
print img.size #Get the width and height of the image for iterating over
print pix[15,15] #Get the RGBA Value of the a pixel of an image
pix[15, 15] = value # Set the RGBA Value of the image (tuple)
img.save("out.jpg") # Saves the modified pixels to image 

【讨论】:

  • 我从来没有安装过 PIL,因为我运行的是 python 3 并且它没有在 pip 中列出。
  • 我尝试了pip uninstall pillow,然后又尝试了pip install pillow,但还是不行。
  • 尝试手动下载然后安装。 python setup.py install
  • 从 pip 卸载它并使用 easy_install 重新安装后,它似乎可以工作了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-10-11
  • 2021-06-01
  • 2016-11-19
  • 2017-07-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多