如何使用python的PIL以一定角度绘制文本? [英] How do I draw text at an angle using python's PIL?

查看:428
本文介绍了如何使用python的PIL以一定角度绘制文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Python,我希望能够使用PIL以不同角度绘制文本.

Using Python I want to be able to draw text at different angles using PIL.

例如,假设您正在围绕时钟的表面绘制数字.数字 3 将会出现,而 12 则将我们逆时针旋转90度.

For example, imagine you were drawing the number around the face of a clock. The number 3 would appear as expected whereas 12 would we drawn rotated counter-clockwise 90 degrees.

因此,我需要能够以许多不同的角度绘制许多不同的弦.

Therefore, I need to be able to draw many different strings at many different angles.

推荐答案

将文本绘制到一个临时的空白图像中,旋转它,然后将其粘贴到原始图像上.您可以将这些步骤包装在一个函数中.祝您好运,确定要使用的确切坐标-我的冷雾脑袋现在还不适应.

Draw text into a temporary blank image, rotate that, then paste that onto the original image. You could wrap up the steps in a function. Good luck figuring out the exact coordinates to use - my cold-fogged brain isn't up to it right now.

此演示在图像上方倾斜显示黄色文本:

This demo writes yellow text on a slant over an image:

# Demo to add rotated text to an image using PIL

import Image
import ImageFont, ImageDraw, ImageOps

im=Image.open("stormy100.jpg")

f = ImageFont.load_default()
txt=Image.new('L', (500,50))
d = ImageDraw.Draw(txt)
d.text( (0, 0), "Someplace Near Boulder",  font=f, fill=255)
w=txt.rotate(17.5,  expand=1)

im.paste( ImageOps.colorize(w, (0,0,0), (255,255,84)), (242,60),  w)

这篇关于如何使用python的PIL以一定角度绘制文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆