Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python-如何将字符串转换为文本的PNG_Python_String_Png_Thumbnails - Fatal编程技术网

Python-如何将字符串转换为文本的PNG

Python-如何将字符串转换为文本的PNG,python,string,png,thumbnails,Python,String,Png,Thumbnails,我正在构建一个缩略图创建程序,我需要将字符串转换为该字符串的图像,以便可以将其粘贴到缩略图中。我正在使用PIL图像模块处理我的图像 例如,如果给我一个“#53”字符串,我希望能够创建该字符串的PNG,以便将其放在缩略图的右下角。我目前的计划是在一个文件夹中创建一个包含每个字符的PNG,然后循环遍历字符串并将单个字符的图像缝合在一起,直到整个字符串缝合在一起。然而,这似乎有点草率,而且很难更改字体,甚至很难为每个字母找到这样一个PNG库。有什么建议吗?PIL直接做你想做的事。从文件来看 使用PIL

我正在构建一个缩略图创建程序,我需要将字符串转换为该字符串的图像,以便可以将其粘贴到缩略图中。我正在使用PIL图像模块处理我的图像


例如,如果给我一个“#53”字符串,我希望能够创建该字符串的PNG,以便将其放在缩略图的右下角。我目前的计划是在一个文件夹中创建一个包含每个字符的PNG,然后循环遍历字符串并将单个字符的图像缝合在一起,直到整个字符串缝合在一起。然而,这似乎有点草率,而且很难更改字体,甚至很难为每个字母找到这样一个PNG库。有什么建议吗?

PIL直接做你想做的事。从文件来看


使用PIL,您可以将字符串写入文本,并将结果保存为PNGH ImageDraw如何找到我想要的字体?程序正在抛出错误,因为它找不到字体。我把它放在程序存储的文件夹中,我也使用了.otf,这是导致错误的原因吗?文档中介绍了ThanksHow设置字体(枕头文档可能会更新:)
import ImageFont, ImageDraw

draw = ImageDraw.Draw(image)

# use a bitmap font
font = ImageFont.load("arial.pil")

draw.text((10, 10), "hello", font=font)

# use a truetype font
font = ImageFont.truetype("arial.ttf", 15)

draw.text((10, 25), "world", font=font)