Skip to main content

CiHuang (雌黄) - SVG Element Editor

Click any single element of an SVG and move it, repaint it, reshape it, or rewrite its text.

CiHuang (雌黄) is the yellow mineral scholars once used as correction fluid: you brush it over a wrong character and write the right one on top. This tool does the same to a drawing -- pick one piece, fix it, leave everything else untouched.

中文说明

Features

  • Open any SVG -- a real SVG file is parsed as XML, not flattened to an image.
  • Click to select one element -- hit-testing walks the elements in reverse paint order and tests actual pixels, so you select the shape you see, not its bounding box.
  • Drag to move -- the move is written as a translate(...) on that element only.
  • Repaint -- set fill and stroke with a color picker, or clear them to none.
  • Reshape -- an editable table exposes every raw attribute (cx, r, d, points, transform, ...), so any geometry can be changed.
  • Edit text -- rewrite the content of <text> elements.
  • Duplicate / delete / undo / redo, save as SVG, export to PNG.
  • Scriptable -- the same operations are available from the CLI, a Python API and an OpenAI function-calling tool set.

Limitations

Worth knowing before you rely on it:

  • Hit-testing renders each candidate to a raster capped at 1600 px, so a few clicks on a very large document can feel slow the first time; results are cached afterwards.
  • Editing <text> replaces any <tspan> children with a single text run.
  • The tool edits elements in place. It does not re-parent, re-order or group elements, and it does not touch viewBox, stylesheets inside <style>, or animations.
  • <image> and <use> can be moved and recolored but their referenced content is not edited.
  • It is an annotator, not a full vector editor: no bezier-point editing, no snapping.

Requirements

  • Python 3.10+
  • PySide6 (installed automatically)

Installation

From PyPI:

pip install cihuang

From source:

git clone https://github.com/CodeOfMe/CiHuang.git
cd CiHuang
pip install -e .

Quick Start

# Open the graphical editor
cihuang gui examples/sample.svg

# Or just list the editable elements of a file
cihuang info examples/sample.svg

CiHuang GUI

Usage

GUI

cihuang gui drawing.svg
# or, equivalently:
cihuang-gui drawing.svg

Left mouse button selects and drags an element. Middle mouse button pans. The mouse wheel zooms. The right dock edits fill, stroke, text and raw attributes; the left dock lists every element.

CLI

# List elements (add --json for machine output)
cihuang info drawing.svg

# Set the fill of element 3, writing drawing-edited.svg
cihuang fill drawing.svg 3 "#ff6600"

# Recolor the stroke instead, to an explicit output path
cihuang fill drawing.svg 3 "#003366" --stroke -o out.svg

# Clear an element's fill
cihuang fill drawing.svg 3

# Move element 1 by dx=20, dy=-5
cihuang move drawing.svg 1 20 -5

# Rewrite the text of element 5
cihuang text drawing.svg 5 "New label"

# Delete element 0
cihuang remove drawing.svg 0

Python API

from cihuang import SvgDocument, cihuang_set_color

# One-shot, writes drawing-edited.svg
result = cihuang_set_color(input_path="drawing.svg", element_index=3, color="#ff6600")
print(result.success)   # True / False
print(result.data)      # {"output": "...", "index": 3, "prop": "fill", "color": "#ff6600"}

# Or drive the document directly, then save wherever you like
doc = SvgDocument.load("drawing.svg")
doc.push_undo()
doc.set_color(3, "fill", "#ff6600")
doc.translate(3, 20, -5)
doc.set_text(5, "New label")
doc.save("out.svg")

Agent Integration

The TOOLS list exposes the same operations for OpenAI function calling.

from cihuang.tools import TOOLS, dispatch

payload = dispatch("cihuang_inspect", {"input_path": "drawing.svg"})
print(payload["success"])

Development

pip install -e ".[dev]"
ruff format . && ruff check . && pytest

License

GPL-3.0-or-later. See LICENSE.

Metadata

Release files for cihuang 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cihuang 0.1.0
File Size Uploaded
cihuang-0.1.0.tar.gz 34.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cihuang 0.1.0
File Interpreter ABI Platform
cihuang-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 67.7 kB

Release files / cihuang-0.1.0.tar.gz

Download URL cihuang-0.1.0.tar.gz
Size 34.8 kB
Tags Source
SHA-256 checksum
How to use checksums
bc2e95ac455c10b6cfdc2e64d0a60912c230add8c388af1926ad2112db261f77
BLAKE2b-256 checksum
How to use checksums
aacc03fcb7cefc7e64e85ed9b42cb5e194ada60a21022004cda17d123e3a501d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.12

Release files / cihuang-0.1.0-py3-none-any.whl

Download URL cihuang-0.1.0-py3-none-any.whl
Size 32.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d846550aa0d5360ebac85864d7cce46caf66d08b7183e60a098a7e6fe8a37f84
BLAKE2b-256 checksum
How to use checksums
382e2f5edc2427ee01286c92ecd2260ea087b918f1767e265604daecd3ccbf83
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.12

Release history Release notifications | RSS feed

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page