如果图像大小足够大,PIL,Image,ImageDraw不会粘贴文本

时间:2017-10-06 18:48:57

标签: python image python-imaging-library

我使用Python Imaging Library遇到了一个奇怪的问题。以下是我用于重现性的确切代码(在ipython中),最后的版本有助于澄清:

Python 3.5.3 |Continuum Analytics, Inc.| (default, Mar  6 2017, 11:58:13) 
Type 'copyright', 'credits' or 'license' for more information
IPython 6.1.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from PIL import (Image, ImageDraw)

In [2]: def title_text(height):
   ...:     im = Image.new(mode='L', size=(516,height), color=255)
   ...:     draw = ImageDraw.Draw(im)
   ...:     draw.text((0,0), "Title Text")
   ...:     im.save("test_"+str(height)+".png")
   ...:     

In [3]: title_text(100)

In [4]: title_text(50000)

In [5]: import PIL

In [6]: PIL.__version__
Out[6]: '4.1.1'

我得到的输出非常奇怪。对于第一张图片,我已将其附在此处:

enter image description here

您可以在此处看到“标题文字”成功显示。

但是当我为高度为50k像素的图像做同样的事情时,由于某种原因标题文字无处可见。到处都是纯白色的图像;尽管滚动到顶部并放大,但​​我看不到文字。我曾经能够获得更大的图像(高度远远大于50k像素)并粘贴在它们上面,但这似乎不起作用。

(1)任何人都可以重现这个结果吗? (2)关于为什么这可能不起作用的任何想法?

1 个答案:

答案 0 :(得分:1)

这可能是你的观众。如果我在Chrome中打开 test_50000.png 并将其放大到500%,我会看到顶部的小文字。