SVG API

SVG API

Optimize SVG markup with SVGO presets and encode any image as a clean, CSS-ready data URI — over a simple JSON REST contract.

Two endpoints, one job: shrink SVG markup or wrap any image as a data: URI for inline embedding. Both run server-side, so output is deterministic and identical across browsers.

# Optimize an SVG snippet
curl -X POST https://jinero.online/api/v1/svg/optimize \
  -H "Content-Type: application/json" \
  -d '{"svg": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"M12 2L2 22h20z\"/></svg>", "preset": "balanced"}'
const r = await fetch("https://jinero.online/api/v1/svg/optimize", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ svg: source, preset: "balanced" }),
});
const { output, savings_percent } = await r.json();

All endpoints are public — no key required. Operations are stateless and cheap, so limits are generous.

# Anonymous limits (per IP):
#   POST /svg/optimize    30 req/min
#   POST /svg/to-datauri  30 req/min
#   GET  /svg/presets     60 req/min

# Max SVG body: 500,000 chars (~500 KB)

Run SVG markup through SVGO with one of three presets. Removes metadata, collapses transforms, rounds path data — typically 30-60% smaller without visual changes.

POST https://jinero.online/api/v1/svg/optimize
ParameterTypeDescription
svg string SVG markup (with or without XML prolog). Max 500,000 chars.
preset string safe (minimal cleanup), balanced (default — best size/safety ratio), aggressive (max compression, may alter rendering for filter-heavy SVGs).
curl -X POST https://jinero.online/api/v1/svg/optimize \
  -H "Content-Type: application/json" \
  -d @- <<JSON
{
  "svg": "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\"><circle cx=\"12\" cy=\"12\" r=\"10\" fill=\"red\"/></svg>",
  "preset": "aggressive"
}
JSON
const r = await fetch("https://jinero.online/api/v1/svg/optimize", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ svg: source, preset: "aggressive" }),
});
const data = await r.json();
console.log(`-${data.savings_percent}%`);
$res = Http::post("https://jinero.online/api/v1/svg/optimize", [
    "svg" => $svgSource,
    "preset" => "balanced",
]);
$optimized = $res->json("output");
Example response
{
  "success": true,
  "preset": "aggressive",
  "output": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><circle cx=\"12\" cy=\"12\" r=\"10\" fill=\"red\"/></svg>",
  "original_size": 132,
  "optimized_size": 70,
  "savings_bytes": 62,
  "savings_percent": 46.97
}

Wrap an image as a data: URI ready to drop into CSS background-image, HTML src, or SVG href. Accepts raw SVG text, an uploaded file (svg/png/jpg/gif/webp), or a URL to fetch.

POST https://jinero.online/api/v1/svg/to-datauri
ParameterTypeDescription
svg string Raw SVG text. Mutually exclusive with image/url.
image file (multipart) Upload an svg/png/jpg/gif/webp file. Max 5 MB.
url string Public image URL to fetch. Max 2048 chars.
options.encoding string utf8 (default for SVG, smaller in CSS) or base64 (default for raster).
options.quotes string single or double (default) — affects escaping of attribute quotes inside the data URI.
# Option 1: raw SVG text
curl -X POST https://jinero.online/api/v1/svg/to-datauri \
  -H "Content-Type: application/json" \
  -d '{"svg": "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\"><circle cx=\"12\" cy=\"12\" r=\"10\" fill=\"red\"/></svg>"}'

# Option 2: file upload
curl -X POST https://jinero.online/api/v1/svg/to-datauri \
  -F "[email protected]"

# Option 3: URL fetch
curl -X POST https://jinero.online/api/v1/svg/to-datauri \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com/icon.png"}'
// Inline SVG → CSS data URI
const r = await fetch("https://jinero.online/api/v1/svg/to-datauri", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    svg: svgSource,
    options: { encoding: "utf8", quotes: "double" },
  }),
});
const { data_uri, css } = await r.json();
// data_uri  → use anywhere
// css       → background-image: url("…");
Example response
{
  "success": true,
  "data_uri": "data:image/svg+xml,%3Csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\"%3E%3Ccircle cx=\"12\" cy=\"12\" r=\"10\" fill=\"red\"/%3E%3C/svg%3E",
  "css": "background-image: url(\"data:image/svg+xml,…\")",
  "mime": "image/svg+xml",
  "encoding": "utf8",
  "input_size": 132,
  "output_size": 187
}

Returns the available presets plus a short human-readable description — useful for populating settings UIs.

GET https://jinero.online/api/v1/svg/presets
curl https://jinero.online/api/v1/svg/presets
const r = await fetch("https://jinero.online/api/v1/svg/presets");
const { presets } = await r.json();
Example response
{
  "presets": [
    { "key": "safe",       "name": "Safe",       "description": "Minimal optimization, preserves most attributes" },
    { "key": "balanced",   "name": "Balanced",   "description": "Good compression with minimal visual changes" },
    { "key": "aggressive", "name": "Aggressive", "description": "Maximum compression, may affect some SVG features" }
  ]
}

Standard HTTP semantics. Errors return JSON with a "message" field.

// 422 — validation (oversized SVG, unknown preset, invalid URL)
{ "message": "The preset field must be one of: safe, balanced, aggressive." }

// 422 — input missing on /to-datauri
{ "message": "Provide one of: svg (text), image (file), or url" }

// 422 — SVGO crashed on malformed markup
{ "message": "Invalid SVG: unexpected end of input" }

// 429 — rate limit exceeded
{ "message": "Too Many Attempts." }

About the jinero.online SVG API

Free REST API for SVG optimization and data-URI encoding — same SVGO engine as everyone else, plus a unified to-datauri endpoint that accepts text, files, or URLs.

SVGO under the hood

The optimizer is SVGO with three carefully tuned preset profiles — same engine as the popular SVGOMG site, exposed as a REST API.

Three inputs, one endpoint

/svg/to-datauri accepts raw markup, a file upload, or a fetch URL — pick whichever fits the request you already have.

CSS-ready output

Data URI responses include a pre-formatted CSS snippet so you can drop the result straight into a stylesheet without escaping.

No file storage

Optimization is fully in-memory. Uploaded files are deleted as soon as the response is built — nothing to clean up afterward.

Frequently Asked Questions

No. The SVG API is public and rate-limited per IP — 30 requests/minute on /optimize and /to-datauri, 60 on /presets.

"balanced" is the right default — it removes metadata, rounds numeric precision, and collapses transforms but never alters rendering. Use "aggressive" only when you control the SVG and have visually compared output, since it can remove filter primitives and merge paths.

For SVGs, utf8 (URL-encoded) is smaller and CSS-friendly — that is the default. For binary formats like PNG, JPG, or WebP, base64 is the only option and we apply it automatically.

SVG markup: 500,000 characters (~500 KB). File uploads (image field): 5 MB. URL fetches: no hard cap on the remote file but we abort if the response exceeds 5 MB.

With "safe" and "balanced" presets, yes — output renders identically in modern browsers. "aggressive" may drop filter primitives, merge similar paths, and round coordinates more heavily, which can affect rendering for filter-driven SVGs. Always preview after switching presets.