有什么好的python库,可以生成和渲染图像格式的文本? [英] Is there any good python library for generating and rendering text in image format?

查看:85
本文介绍了有什么好的python库,可以生成和渲染图像格式的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发类似CMS的应用程序,用户应该能够按照自己的方式创建菜单.理想情况下,每个菜单对象都不是带有背景的文本,而是文本的图像.我通过以下两种方式中的任何一种来实现此目的:

I'm developing a CMS like application where the user should be able to create the menu the way he wants. Ideally, each menu object wouldn't be a text with a background but rather an image of the text. I envision this in either of these 2 ways:

a)通过在一个/多个图像文件中用每个字母渲染一个字体,并给出一个单词的脚本会给我要么将图像序列串在一起,要么给我一个带有所有字母组合的图像文件.我知道可以手动完成此操作,但我觉得可能有一个库可以对此提供帮助.

a) By rendering a font in a/several image file/s with every letter and a script that given a word would give me either the sequence of images to string together or a single image file with the combination of all letters. I understand this could be done manually, but I feel there's probably a library to help with this.

b)借助某种成像库,该库可以渲染具有多种混合效果(例如渐变色,阴影,辉光等)的文本.虽然我认为这要难一些,但也许有些东西可以满足这种需求.

b) With some kind of imaging library that would be able to render text with several blending effects such as gradient color, shadows, glow, etc. While I believe this one's a bit harder, maybe there's something that suits this need.

在执行此操作或类似操作的任何库中有任何提示吗?

Any tips on any library that does this or anything similar?

提前谢谢!

布鲁诺

推荐答案

尽管如今我已经决定使用网络字体和CSS,但几年前我遇到了这个问题,并整理了一个小型项目,该项目可以生成文本-​​根据传递的URL参数在文件中的模板图像中.

Although nowadays I'd settle to go with web fonts and CSS,a couple of years ago I faced this problem, and put together a small project that would generate text-within a templated image on the file, according to passed URL parameters.

该项目仍在此处发布: https://bitbucket.org/jsbueno/dynabutton -它可以作为CGI脚本使用,但是可以很容易地适应于与效率更高的服务器一起使用(如果您将其置于联机状态,我也建议您进行一些安全调整).您还可以使用它来生成带有服务器端脚本的所有图像,并将生成的图像文件在线.

The project is still publicized here: https://bitbucket.org/jsbueno/dynabutton -- it is made to work as a CGI script, but could be easily adapted to work with a more eficient server (I'd recomend some security tunning as well, if you are putting it online). You can also use it to generate all your images with a server side script, and just put the resulting image files online.

(确实在下面使用PIL)

(it does use PIL underneath)

是的,它可以进行阴影处理并使用适当的参数发光,可以使用任何服务器安装的字体,并使用图像模板来提供背景,因此您可以手动应用任何效果. (不过,其中包括的模板是相当业余的)

Ah yes, it can do shadow, and glow with proper parameters, can use any server-installed font, and will use an image template for providing the background, so you can apply any effect manually. (the included temlates, though, are quite amateurish)

这篇关于有什么好的python库,可以生成和渲染图像格式的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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