Skip to content

Instantly share code, notes, and snippets.

@hhatto
Created April 30, 2015 01:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hhatto/69b3f3541ac994ef59df to your computer and use it in GitHub Desktop.
Save hhatto/69b3f3541ac994ef59df to your computer and use it in GitHub Desktop.
generate image for stroke width 2.0 and 3.0 on Python (pgmagick)
import pgmagick as pg
def gen_line_png(line_width):
img = pg.Image(pg.Geometry(200, 200), "white")
img.type(pg.ImageType.TrueColorMatteType)
coords = pg.CoordinateList()
drawables = pg.DrawableList()
blankColor = pg.Color()
ptColor = pg.Color("magenta")
lineColor = pg.Color("red")
drawables.push_back(pg.DrawableFillColor(ptColor))
drawables.push_back(pg.DrawableStrokeColor(ptColor))
for x, y in [(50, 50), (75, 60), (100, 80), (150, 150), (150, 30), (180, 10)]:
coords.push_back(pg.Coordinate(x, img.size().height() - y))
r = 1.0
y = img.size().height() - y
drawables.push_back(pg.DrawableCircle(x, y, x + r, y + r))
drawables.push_back(pg.DrawableFillColor(blankColor))
drawables.push_back(pg.DrawableStrokeColor(lineColor))
drawables.push_back(pg.DrawableStrokeLineJoin(pg.LineJoin.RoundJoin))
drawables.push_back(pg.DrawableStrokeWidth(line_width))
drawables.push_back(pg.DrawablePolyline(coords))
img.draw(drawables)
img.write('test%d.png' % int(line_width))
for w in (1.0, 2.0, 3.0, 4.0, 5.0, 10.0):
gen_line_png(w)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment