1. Local File Selection & Input Reading
When you choose an SVG file, drag it into the dropzone, or paste raw XML markup, the browser reads the
text directly from memory via the standard FileReader API. Files larger than 10 MB or
non-SVG file types are stopped immediately before parsing.
2. XML Validation & Security Sanitization
Because SVG is an XML document format, raw SVG files can sometimes contain scripts or external URLs.
Before rendering anything, the converter runs DOMParser in strict image/svg+xml
mode to verify valid XML syntax and confirm a root <svg> element exists. It rejects
custom XML entity declarations and strips potentially unsafe elements (<script>,
<foreignObject>, <iframe>), inline on* event
attributes, and external http(s):// references.
3. Dimension Detection & Aspect Ratio Control
The parser inspects explicit width and height attributes (supporting px,
pt, in, cm, and mm) as well as the SVG
viewBox attribute. When aspect ratio locking is active, changing either target dimension
recalculates the paired dimension proportionally. If you select a preset whose aspect ratio differs from
your SVG (for instance, placing a square icon into a 1920 × 1080 canvas), the graphic is
proportionally centered inside the frame so nothing stretches.
4. Browser Rendering & Canvas Rasterization
Rather than inserting untrusted SVG markup into the active webpage DOM, the serialized SVG string is
turned into an isolated in-memory Blob URL and loaded into an offscreen Image
object. Once decoded, the converter initializes an offscreen <canvas> at your chosen
width and height:
- Transparent mode: Leaves the canvas alpha channel clear so open areas remain transparent.
- White or Custom Color mode: Fills the entire target canvas with your chosen solid color before drawing the SVG artwork on top.
5. PNG Encoding & Download
Finally, canvas.toBlob(..., 'image/png') encodes the rasterized pixels into a genuine
lossless PNG file. In Single File mode, you can preview the PNG over a checkerboard transparency grid,
customize the filename, copy the PNG to your clipboard (in supported browsers), or download it directly. In
Batch Queue mode, converted PNG buffers can also be bundled in memory into a standard .zip
file using pure JavaScript.