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.
  • Smart Group -- Ctrl+Alt+G clusters objects that sit close together (a figure and its caption, say) and groups them automatically.
  • No accidental backdrop grab -- a click on a full-canvas background reads as a click on empty space; select the backdrop from the element list when you mean to.
  • 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 gently and is limited so the drawing cannot shrink away. Ctrl+G groups the selection, Ctrl+Shift+G ungroups it and Ctrl+Alt+G smart-groups nearby objects. 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.1

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.1
File Size Uploaded
cihuang-0.2.1.tar.gz 39.9 kB Details

Built distribution (wheel)

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

Total release size: 77.4 kB

Release files / cihuang-0.2.1.tar.gz

Download URL cihuang-0.2.1.tar.gz
Size 39.9 kB
Tags Source
SHA-256 checksum
How to use checksums
3c759929a3ce67d7b2c187639036963855d509330e95ad4d63c9281cdf4b65e5
BLAKE2b-256 checksum
How to use checksums
6ec89eb14f428668ef0b07eebada109c769e343db1c54f19b495116d3286afee
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.1-py3-none-any.whl

Download URL cihuang-0.2.1-py3-none-any.whl
Size 37.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
47c9a83d7b264a3b49f1560539a0e7ffc4fb238a10c070c5fdd88850ad255c24
BLAKE2b-256 checksum
How to use checksums
12dc5138928bb0c044b03ec1d22f30bc470ce7be3e8d27c361e69a7d7c7c804f
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

This release

0.2.1 This release

2 release files

0.2.0

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