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.
  • Select a group of things -- Shift-click to add, or drag a marquee box around several shapes (for example a figure and its caption), then move them together.
  • Group / ungroup -- Ctrl+G wraps the selection in a <g> (clicking then picks the whole group, like Inkscape); Ctrl+Shift+G dissolves it.
  • 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 900 px; only elements whose bounding box contains the click are rasterised, so it stays quick on large files.
  • Editing <text> replaces any <tspan> children with a single text run.
  • Grouping requires the selected elements to share the same parent; the tool does not re-order elements across groups.
  • 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. Drag on empty space to marquee-select; hold Shift to add to the selection. Middle button pans, the wheel zooms, Ctrl+G groups the selection and Ctrl+Shift+G ungroups it. 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.2.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.2.0
File Size Uploaded
cihuang-0.2.0.tar.gz 37.6 kB Details

Built distribution (wheel)

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

Total release size: 72.9 kB

Release files / cihuang-0.2.0.tar.gz

Download URL cihuang-0.2.0.tar.gz
Size 37.6 kB
Tags Source
SHA-256 checksum
How to use checksums
6322495ac860c0670d12371d2270d4b034f92c0f0cde0fdfceb7d1a525df6fb9
BLAKE2b-256 checksum
How to use checksums
d6c40498cde6d5539132a25b86b81aa0ba95640d55b4a894d31fb82bb9c51f75
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.2.0-py3-none-any.whl

Download URL cihuang-0.2.0-py3-none-any.whl
Size 35.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ee98cc33de613cc2724d8b6e6ed529e06ff58b3a997272bde3f6af11d5c52e95
BLAKE2b-256 checksum
How to use checksums
00297bc3f8c58c4238c8068aa7e71fdb508e25ba19d36e29fa65f710d4ce806e
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

This release

0.2.0 This release

2 release files

0.1.0

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