How can I draw text with different stroke and fill colors on images with python?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How can I draw text with different stroke and fill colors on images with python? Here is some text with red stroke and gray fill. I tried to do this with PIL but there was no option for setting the stroke color. 回答1: Using cairo (with much code taken from here ): import cairo def text_extent(font, font_size, text, *args, **kwargs): surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 0, 0) ctx = cairo.Context(surface) ctx.select_font_face(font, *args, **kwargs) ctx.set_font_size(font_size) return ctx.text_extents(text) text='Example' font="Sans