PIL中的字体? [英] fonts in PIL ?

查看:101
本文介绍了PIL中的字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



大家好,


我正在写(在Linux Redhat 9上)

一些使用PIL制作图表的脚本从一组点开始。


一切都还好,除了PIL似乎没有字体。

我在哪里可以喜欢一些?

另外,是否有一些在PIL中使用字体的真实例子?


文档说的如下:


Hello all,

I am writing (on Linux Redhat 9)
some script to make graphs using PIL, from a set of points.

All is ok, except that there seems to be no font coming with PIL.
Where could I fond some ?
Also, are there some real examples of use of fonts in PIL ?

Documentation says something like:

加载
ImageFont.load(file)=>字体实例

从给定文件加载字体,并返回相应的字体对象。如果此函数失败,则会引发IOError异常。


但是应该归档是字体的完整路径,

或只是字体名称?


方法truetype的相同问题:

truetype
ImageFont.truetype(文件,大小)=>字体实例

加载TrueType或OpenType字体文件,并创建字体对象。此
函数从给定文件加载字体对象,并为给定大小的字体创建字体对象。
在Windows上,如果给定的文件名不存在,加载程序也会在Windows字体目录中显示
load
ImageFont.load(file) => Font instance

Loads a font from the given file, and returns the corresponding font
object. If this function fails, it raises an IOError exception.
but should "file" be the full path to the font,
or just a font name ?

Same question for method truetype:
truetype
ImageFont.truetype(file, size) => Font instance

Load a TrueType or OpenType font file, and create a font object. This
function loads a font object from the given file, and creates a font
object for a font of the given size. On Windows, if the given file name does not exist, the loader also looks
in Windows fonts directory.



另外,只能调整真实类型字体的大小:

有没有简单的方法来调整标准字体的大小?

(我不是字体专家:))

提前感谢您的支持答案。

问候,


-

Stephane Ninin




Also, only true type fonts can be resized:
there is no easy way to resize standard fonts ?
(I am not a font expert :) )
Thanks in advance for your answers.
Regards,

--
Stephane Ninin



推荐答案

StéphaneNinin< st ***** @ alussinan.org> pisze:
Stéphane Ninin <st*****@alussinan.org> pisze:
一切都还好,除了PIL似乎没有字体。
我在哪里可以喜欢一些?
All is ok, except that there seems to be no font coming with PIL.
Where could I fond some ?



http://effbot.org - 在下载部分查找pilfonts。


-

Jarek Zgoda
http://jpa.berlios.de/



http://effbot.org -- look for pilfonts in download section.

--
Jarek Zgoda
http://jpa.berlios.de/


还有Jarek Zgoda:
Also sprach Jarek Zgoda :
一切都还好,除了PIL似乎没有字体。
我在哪里可以喜欢一些?
All is ok, except that there seems to be no font coming with PIL.
Where could I fond some ?



http://effbot.org - 在下载部分查找pilfonts。



http://effbot.org -- look for pilfonts in download section.




非常感谢。

似乎有足够的选择,所以我甚至不需要调整文本大小。



Thanks a lot.
Seems there is enough choice so that I wont even need to resize text.


| ....

|另外,在PIL中是否有一些使用字体的真实例子?

| ....

$ b $bStéphanie....


以下是使用PIL ImageFont类的示例....


'''''

模块....... pil_ImageFont.py

Code_By ...... Stanley C. Kitching

Code_Date .... 2004-02-09

'''''

导入图片

导入ImageFont

导入ImageDraw


this_list = ["看,在天空中......... ,

"它是一只鸟................" ,

"这是一架飞机............... ,

"这是你的事啊!!!!! " ,

" " ,

"更强大的 ,

"比机车!!!!!! ,

" " ,

"能够跨越高层建筑 ,

"在一个单一的界限!!!!!! ]


this_image = Image.new(''RGB'',(360,240))


#调整dir_PIL路径到你的安装


dir_PIL =''K:/ Python23 / Lib / site-packages / PIL /''


dir_fonts = dir_PIL +''pilfonts /''


this_font =''courB12.pil''


i_font = ImageFont.load(dir_fonts + this_font)


this_col = 10

this_row = 10

row_inc = 20


for this_line in this_list:


i_draw = ImageDraw.Draw(this_image)

i_draw.text((this_col,this_row),this_line,font = i_font)


this_row + = row_inc


this_image.save(''pil_ImageFont.png'')


this_image.show()


-

Cousin Stanley

人类

凤凰城,亚利桑那州

| ....
| Also, are there some real examples of use of fonts in PIL ?
| ....

Stéphanie ....

Following is an example of using the PIL ImageFont class ....

''''''
Module ....... pil_ImageFont.py
Code_By ...... Stanley C. Kitching
Code_Date .... 2004-02-09
''''''

import Image
import ImageFont
import ImageDraw

this_list = [ " Look, up in the sky ......... " ,
" It''s a bird ................ " ,
" It''s a plane ............... " ,
" It''s S u p e r M a n !!!!! " ,
" " ,
" More powerful" ,
" than a locomotive !!!!!!" ,
" " ,
" Able to leap tall buildings" ,
" in a single bound !!!!!!" ]

this_image = Image.new( ''RGB'' , ( 360 , 240 ) )

# Adjust dir_PIL path to YOUR installation

dir_PIL = ''K:/Python23/Lib/site-packages/PIL/''

dir_fonts = dir_PIL + ''pilfonts/''

this_font = ''courB12.pil''

i_font = ImageFont.load( dir_fonts + this_font )

this_col = 10
this_row = 10
row_inc = 20

for this_line in this_list :

i_draw = ImageDraw.Draw( this_image )

i_draw.text( ( this_col , this_row ) , this_line , font = i_font )

this_row += row_inc

this_image.save( ''pil_ImageFont.png'' )

this_image.show()

--
Cousin Stanley
Human Being
Phoenix, Arizona


这篇关于PIL中的字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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