简体   繁体   English

Python:任何不使用 PIL 在图像上绘制文本的想法

[英]Python : any ideas without using PIL to draw the text on a image

im using Python 3.3,and i have installed(just excute the downloaded file .exe,no need any setting?) aspell PIL from below link,unfortunately i import PIL are error unresolved PIL.我使用的是 Python 3.3,我已经安装了(只执行下载的文件 .exe,不需要任何设置?)从下面的链接中的 aspell PIL,不幸的是我导入 PIL 是错误未解决的 PIL。 why?为什么?

http://www.lfd.uci.edu/~gohlke/pythonlibs/ http://www.lfd.uci.edu/~gohlke/pythonlibs/

import PIL
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
font = ImageFont.truetype("C:/arial.ttf",25)
img=Image.new("RGBA", (200,200),(120,20,20))
draw = ImageDraw.Draw(img)
draw.text((0, 0),"This is a test",(255,255,0),font=font)
draw = ImageDraw.Draw(img)
draw = ImageDraw.Draw(img)
img.save("a_test.png")

or have any ideas without using PIL to draw the text on a image?或者有什么想法而不使用 PIL 在图像上绘制文本?

Because it haven't been released for 3.3 yet.因为它还没有在 3.3 中发布。

"The current free version is PIL 1.1.7. This release supports Python 1.5.2 and newer, including 2.5 and 2.6. A version for 3.X will be released later." “当前的免费版本是 PIL 1.1.7。此版本支持 Python 1.5.2 及更新版本,包括 2.5 和 2.6。稍后将发布 3.X 版本。” -taken from PILs homepage. - 取自 PILs 主页。

If you want to use PIL use Python 2.6.如果要使用 PIL,请使用 Python 2.6。 The 3.X version of Python changed python a bit so it's not fully backwards compatible. Python 的 3.X 版本对 python 进行了一些更改,因此它不完全向后兼容。

I recommend you use older version of Python instead of 3.X, unless you have a REALLY good reason to use 3.X.我建议您使用旧版本的 Python 而不是 3.X,除非您有充分的理由使用 3.X。

Pillow is the continuation of Python Imaging Library that has been updated to work with Python 3. This should fix your unresolved PIL problem. Pillow是 Python Imaging Library 的延续,该库已更新为可与 Python 3 一起使用。这应该可以解决您未解决的 PIL 问题。

Other options for drawing text on an image in recent Python exist:在最近的 Python 中,存在在图像上绘制文本的其他选项:

  • Pygame is an SDL 1.2 wrapper that supports Python 3 since Pygame 1.9.2. Pygame是一个 SDL 1.2 包装器,从 Pygame 1.9.2 开始就支持 Python 3。
  • Wand is an ImageMagick wrapper built on ctypes. Wand是一个基于 ctypes 的 ImageMagick 包装器。
  • gdmodule wraps GD, but its installer appears to be Linux-only. gdmodule包装了 GD,但它的安装程序似乎只支持 Linux。 It won't help you under Windows (cf. "C:/arial.ttf" ) but it might help others with the same problem.它不会在 Windows 下帮助你(参见"C:/arial.ttf" ),但它可能会帮助其他有同样问题的人。

Using opencv使用 opencv

import cv2
font = cv2.FONT_HERSHEY_SIMPLEX 
orgin = (50, 50) 
fontScale = 1
color = (255, 0, 0) 
thickness = 2

Using cv2.putText() method使用 cv2.putText() 方法

image = cv2.putText(image, 'OpenCV', org, font, fontScale, color, thickness, cv2.LINE_AA) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM