Letting the Logo Exporter take your own artwork

← Previous Next →
Wishlist · 4 of 6

Letting the Logo Exporter take your own artwork

About a day of work, most of it already done, plus one failure mode that breaks the export silently

Where it stands

The Logo Exporter draws the Areactor mark and exports it as PNG or SVG at a set of useful sizes. Everything except the artwork is already generic: updateGeometry() resizes and recenters, exportAsset() serializes to SVG or rasterizes through a canvas to PNG, the size presets work, and the transparent and dark backgrounds both work.

The only thing hardcoded is the artwork itself, sitting inside #master-gimbal. That is why the page is a demonstration of a capability rather than a tool anyone else can use.

What it needs

A file input for SVG. Read the file as text and put its contents into #master-gimbal.

Coordinate normalizing. This is the actual work. The scaling maths reads:

const scaleFactor = (minDimension / 100) * 0.85;

The literal 100 assumes artwork drawn on a 100 by 100 grid. An uploaded file could be 24 by 24 or 1000 by 1000. Read the uploaded file's own viewBox and scale from that instead.

Sanitizing. An SVG can carry <script> elements, onload handlers and references to external files. Putting a stranger's file straight into the page is an injection hole. It is their own browser and there is no server and no other person's data involved, so the harm is limited, but it matters the moment someone previews a file a client emailed them. Stripping scripts, event handlers and external references is roughly twenty lines.

The failure mode that will waste an afternoon

If an uploaded SVG references an external image, rasterizing it through a canvas taints that canvas, and toBlob() throws a SecurityError. The PNG export then fails with no visible explanation while the SVG export keeps working.

Stripping external references during sanitizing fixes this as a side effect, which is a good reason to do the sanitizing first rather than last.

Separately, any <text> in an uploaded SVG will render with whatever font the visitor's browser has, so the PNG may not match the designer's intent. The standard advice applies: convert text to outlines before uploading, and say so on the page.

Effort

About half a day to a day. The export pipeline is finished. What is new is upload, normalizing and sanitizing.

Worth noting

If this gets built, the Logo Exporter stops being an experiment and becomes a fourth thing that could be sold or given away, and the page would move out of the Experiments section on the home page.