Vector2Raster Pro – SVG to PNG
/* — CSS SEPARATION START — */
@import url(‘https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700&family=Space+Mono:wght@400&display=swap’);:root {
–primary: #6366F1; /* Indigo-500 */
–bg-dark: #0F172A;
}body {
font-family: ‘Inter’, sans-serif;
transition: background-color 0.3s, color 0.3s;
}/* Checkerboard for transparency */
.checkerboard {
background-color: #ffffff;
background-image: linear-gradient(45deg, #e5e7eb 25%, transparent 25%),
linear-gradient(-45deg, #e5e7eb 25%, transparent 25%),
linear-gradient(45deg, transparent 75%, #e5e7eb 75%),
linear-gradient(-45deg, transparent 75%, #e5e7eb 75%);
background-size: 20px 20px;
background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}
.dark .checkerboard {
background-color: #1e293b;
background-image: linear-gradient(45deg, #334155 25%, transparent 25%),
linear-gradient(-45deg, #334155 25%, transparent 25%),
linear-gradient(45deg, transparent 75%, #334155 75%),
linear-gradient(-45deg, transparent 75%, #334155 75%);
}/* Dropzone Active */
.dropzone-active {
border-color: #6366F1 !important;
background-color: rgba(99, 102, 241, 0.1) !important;
transform: scale(1.01);
}/* Dark Mode */
.dark body {
background-color: var(–bg-dark);
color: #F9FAFB;
}
.dark .card {
background-color: #1E293B;
border-color: #334155;
}
.dark input, .dark select {
background-color: #334155;
color: white;
border-color: #475569;
}
/* — CSS SEPARATION END — */
tailwind.config = {
darkMode: ‘class’,
theme: {
extend: {
colors: {
primary: ‘#6366F1’,
}
}
}
}
Render scalable vector graphics into high-resolution PNG images. Scale up to 8x without losing quality.
Output Settings
Resolution Scale
1x (Original Size)
2x (Double Resolution)
4x (High Quality)
8x (Ultra Quality)
Custom Width…
Tip: SVGs are vector-based, so you can scale them up infinitely before saving as PNG to get super sharp images.
Start Over
Drop SVG File Here Convert vector code to image
Select SVG
// — JAVASCRIPT SEPARATION START —// DOM Elements
const dropzone = document.getElementById(‘dropzone’);
const fileInput = document.getElementById(‘fileInput’);
const resultArea = document.getElementById(‘result-area’);
const rasterCanvas = document.getElementById(‘raster-canvas’);
const rasterCtx = rasterCanvas.getContext(‘2d’);
const rasterInfo = document.getElementById(‘raster-info’);
const outScale = document.getElementById(‘out-scale’);
const outWidth = document.getElementById(‘out-width’);let uploadedSVGStr = null;
let isDarkMode = false;// — Event Listeners —
dropzone.addEventListener(‘click’, () => fileInput.click());
dropzone.addEventListener(‘dragover’, (e) => { e.preventDefault(); dropzone.classList.add(‘dropzone-active’); });
dropzone.addEventListener(‘dragleave’, () => dropzone.classList.remove(‘dropzone-active’));
dropzone.addEventListener(‘drop’, (e) => {
e.preventDefault();
dropzone.classList.remove(‘dropzone-active’);
if(e.dataTransfer.files.length) handleFile(e.dataTransfer.files[0]);
});
fileInput.addEventListener(‘change’, (e) => {
if(e.target.files.length) handleFile(e.target.files[0]);
});// Settings Listeners
outScale.addEventListener(‘change’, (e) => {
if(e.target.value === ‘custom’) {
outWidth.classList.remove(‘hidden’);
} else {
outWidth.classList.add(‘hidden’);
}
if(uploadedSVGStr) renderSVGToCanvas();
});
outWidth.addEventListener(‘change’, () => { if(uploadedSVGStr) renderSVGToCanvas(); });// — Functions —function handleFile(file) {
if(!file.type.includes(‘svg’) && !file.name.endsWith(‘.svg’)) {
alert(‘Please upload a valid SVG file.’);
return;
}
const reader = new FileReader();
reader.onload = (e) => {
uploadedSVGStr = e.target.result; // Data URL
resultArea.classList.remove(‘hidden’);
renderSVGToCanvas();
};
reader.readAsDataURL(file);
}function renderSVGToCanvas() {
const img = new Image();
img.onload = () => {
// Determine Output Size
let w = img.width;
let h = img.height;
// Fix for SVGs without explicit size attributes
if(w === 0 || h === 0) { w = 800; h = 600; }const scaleMode = outScale.value;
if(scaleMode === ‘custom’) {
const targetW = parseInt(outWidth.value);
if(targetW > 0) {
const ratio = h / w;
w = targetW;
h = targetW * ratio;
}
} else {
const multiplier = parseInt(scaleMode) || 1;
w *= multiplier;
h *= multiplier;
}// Setup Canvas
rasterCanvas.width = w;
rasterCanvas.height = h;
rasterCtx.clearRect(0, 0, w, h); // Ensure transparency
rasterCtx.drawImage(img, 0, 0, w, h);
rasterInfo.innerText = `Dimensions: ${Math.round(w)} x ${Math.round(h)} px`;
};
img.src = uploadedSVGStr;
}function downloadPNG() {
const link = document.createElement(‘a’);
link.download = `converted.png`;
link.href = rasterCanvas.toDataURL(‘image/png’);
link.click();
}function resetAll() {
uploadedSVGStr = null;
fileInput.value = ”;
resultArea.classList.add(‘hidden’);
}function toggleDarkMode() {
isDarkMode = !isDarkMode;
document.documentElement.classList.toggle(‘dark’);
const icon = document.getElementById(‘theme-icon’);
if(isDarkMode) {
icon.classList.remove(‘fa-moon’);
icon.classList.add(‘fa-sun’);
} else {
icon.classList.remove(‘fa-sun’);
icon.classList.add(‘fa-moon’);
}
}// — JAVASCRIPT SEPARATION END —
About the SVG to PNG tool The SVG to PNG page is part of Articles Stock’s online utilities collection. Use the tool above for the task described in its interface, and check the available file types, settings and output before proceeding. This utility relates to image formats, image conversion and file size.
How to use this tool Review the tool’s supported input and options. Select or enter the required input and choose the settings that suit your task. Run the tool and check the result before saving or sharing it. Related online tools Image Compressor and Image Resizer can help with related tasks.