python画圆填色_如何用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.
解决方案
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"
font_size=55.0
font_args=[cairo.FONT_SLANT_NORMAL]
(x_bearing, y_bearing, text_width, text_height,
x_advance, y_advance) = text_extent(font, font_size, text, *font_args)
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(text_width), int(text_height))
ctx = cairo.Context(surface)
ctx.select_font_face(font, *font_args)
ctx.set_font_size(font_size)
ctx.move_to(-x_bearing, -y_bearing)
ctx.text_path(text)
ctx.set_source_rgb(0.47, 0.47, 0.47)
ctx.fill_preserve()
ctx.set_source_rgb(1, 0, 0)
ctx.set_line_width(1.5)
ctx.stroke()
surface.write_to_png("/tmp/out.png")
python画圆填色_如何用python在图像上绘制不同笔触和填充颜色的文本?相关推荐
- python画圆填色_python turtle我想用五种颜色画五个圆,并且用画圆周的颜色填充,老是出问题,怎么回事,怎么修改?:python教程同心圆...
python turtle画4个同心圆方法 from turtle import * def test(): reset() circle(30,-360) up() goto(0,-10) down ...
- python画圆填色橙色_基于TPC-C基准的Python ORM的性能测试详解
当开发与数据库需要在一起使用的应用程序时,对象关系映射器(ORM)通常用于Python编程中.Python ORM的示例是SQLAlchemy,Peewee,Pony-ORM和Django.选择ORM ...
- python画矩阵热图_如何用python的matplotlib绘制热图
python使用matplotlib绘制热图 python常用的绘图库就是matplotlib,今天在给公司绘图时,偶然间发现matplotlib可以绘制热图,并且十分简洁,拿出来跟大家分享一下.(由 ...
- python画出一个梅花_如何用Python画一棵漂亮的树
Tree 海龟绘图turtle 在1966年,Seymour Papert和Wally Feurzig发明了一种专门给儿童学习编程的语言--LOGO语言,它的特色就是通过编程指挥一个小海龟(turtl ...
- 用python画出简单笑脸_如何用Python画滑稽笑脸!
用turtle画滑稽 from turtle import* setup(600,600,200,200) #脸 penup() goto(-210,0) seth(-90) pendown() pe ...
- 用python画个三维地球_如何用Python制作三维散点图?
你可以用matplotlib为此,matplotlib有一个mplot3d模块,它将完全按照您的要求执行.from matplotlib import pyplot from mpl_toolkits ...
- python画出一个梅花_如何用python画一朵花?
import math try: from swampy.TurtleWorld import * # 需要执行 pip install Swampy except ImportError: from ...
- python画画用哪个软件_如何用python画韦恩图? 使用python的tutul工具,画一朵雏菊花...
使用python的tutul工具,画一朵雏菊花 如何用python画韦恩图?不管什么时候,给心留一点空间.人生一世,不用什么都要去争,不是什么都要去抢,欲望少一点,满足多一点,这样才会活得潇洒一点,人 ...
- 如何用python画小黄人_怎么用python画小黄人
怎么用python画小黄人?TB1免费资源网 前言:TB1免费资源网 还记得小黄人哪只蠢萌蠢萌的单眼小黄人?就是喜欢做什么事都喜欢逞能的那只,下面用Python来实现一下,正在逃跑的小黄人.TB1免费 ...
最新文章
- Xilinx 在文档中所用的 LC(logic cells) 与 LUT之间的换算关系
- Express2.X迁移至3.X注意事项
- div内容设float之后,div的自动高度适应
- JS:js中的复制对象值问题——Object.assign()
- MetaWeblog API中文说明
- Mahout kmeans聚类
- CODEVS——T1519 过路费
- MapServer应用开发平台示例
- 以毒攻毒Fight Fire with Fire: Towards Robust Recommender Systems via Adversarial Poisoning Training论文解读
- mac抹掉磁盘重装系统未能与服务器取得联系_【工具】mac笔记本rm -rf 后 如何恢复删除的文件...
- 编写react组件_s! 这就是为什么ReasonReact是编写React的最佳方法的原因
- 100%在CSS中是什么意思?
- goaccess配置nginx日志解析
- 面向对象分析与设计阅读笔记一
- jsp过滤器一点小结
- 项目涉及到的知识点及项目流程图
- gavin中文是什么意思_Gavin[加文,盖温]英文名的中文翻译意思、发音、来源及流行趋势-千代英文名...
- react 日期格式 排序
- 小米机器人 尘盒配件_小米机器人怎么取出尘盒
- 58上租房显示服务器异常,“58同城租房信息”满是套路,你中招了吗?