Python的简洁矢量图形工具:Gizeh
jopen
10年前
Gizeh是一个用于Python的简洁矢量图形工具。
# Let's draw a red circle ! import gizeh surface = gizeh.Surface(width=320, height=260) # in pixels circle = gizeh.circle(r=30, xy= [40,40], fill=(1,0,0)) circle.draw(surface) # draw the circle on the surface surface.write_to_png("circle.png") # export the surface as a PNG
Gizeh在 cairocffi 模块的基础上编写,它是常用C语言库Cairo的一个Python绑定。Cairo虽然强大,但难于学习和使用。Gizeh在Cairo基础上实现一些类,它其更加直观。
import gizeh # initialize surface surface = gizeh.Surface(width=320, height=260) # in pixels # Now make a shape and draw it on the surface circle = gizeh.circle(r=30, xy= [40,40], fill=(1,1,1)) circle.draw(surface) # Now export the surface surface.get_npimage() # returns a (width x height x 3) numpy array surface.write_to_png("circle.png")