skia-pathops: Skia Path Operations for Python

0.9.2 · active · verified Thu Apr 16

skia-pathops is a Python library that provides access to boolean operations on 2D vector paths using Google's Skia graphics library. It's currently at version 0.9.2, seeing relatively frequent updates that often align with upstream Skia library changes or Python version support.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create two simple rectangular paths and perform a union operation using `OpBuilder`. The result is a new `Path` object representing the combined shape.

from skia_pathops import Path, PathOp, OpBuilder

# Create two simple paths
path1 = Path()
path1.moveTo(0, 0)
path1.lineTo(100, 0)
path1.lineTo(100, 100)
path1.lineTo(0, 100)
path1.close()

path2 = Path()
path2.moveTo(50, 50)
path2.lineTo(150, 50)
path2.lineTo(150, 150)
path2.lineTo(50, 150)
path2.close()

# Perform a union operation
builder = OpBuilder()
builder.op(path1, path2, PathOp.UNION)
union_path = builder.resolve().pop() # resolve returns a list of paths

print(f"Original path 1 contour count: {len(path1.getContours())}")
print(f"Original path 2 contour count: {len(path2.getContours())}")
print(f"Union path contour count: {len(union_path.getContours())}")

# You can inspect the points of the resulting path (simplified output)
first_contour_points = union_path.getContours()[0].points
print(f"First contour points (first 3): {first_contour_points[:3]}")

view raw JSON →