【发布时间】:2017-06-04 15:20:37
【问题描述】:
我正在尝试在 Python 中使用 Pillow 制作完全透明的图像
img2 = PILImage.new('RGBA', (1920, 1080), (0,0,0,0))
img2.save('test.png')
上面的代码是参考创建的: https://pillow.readthedocs.io/en/4.0.x/reference/Image.html#constructing-images
PIL.Image.new(mode, size, color=0)
color – 图像使用什么颜色。默认为黑色。如果给定,这应该是单波段模式的单个整数或浮点值,以及多波段模式的元组(每个波段一个值)。创建 RGB 图像时,您还可以使用 ImageColor 模块支持的颜色字符串。如果颜色为无,则图像未初始化。
https://pillow.readthedocs.io/en/4.0.x/handbook/concepts.html#concept-modes
RGBA(4x8 位像素,带有透明蒙版的真彩色) 上面的代码生成 test.png 一个黑色的图像而不是一个完全透明的图像:
系统信息:
$ pip2.7 freeze | grep -i pillow
Pillow==4.0.0
$ python2.7 -V
Python 2.7.9
$ apt list --installed | grep -i imagemagick
imagemagick/stable,now 8:6.8.9.9-5+deb8u6 amd64 [installed]
imagemagick-6.q16/stable,now 8:6.8.9.9-5+deb8u6 amd64 [installed,automatic]
imagemagick-common/stable,now 8:6.8.
$ convert --version
Version: ImageMagick 6.8.9-9 Q16 x86_64 2016-11-26 http://www.imagemagick.org
$ uname -a
Linux revo-vpn-74 3.16.0-4-amd64 #1 SMP Debian 3.16.36-1+deb8u2 (2016-10-19) x86_64 GNU/Linux
$ cat /etc/*release
PRETTY_NAME="Debian GNU/Linux 8 (jessie)"
NAME="Debian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=debian
HOME_URL="http://www.debian.org/"
SUPPORT_URL="http://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
【问题讨论】:
-
在我的应用程序之外测试下面的代码问题,结果与 Hugo 发布的一样
标签: python python-2.7 imagemagick pillow