返回服务

在线 SVG 编辑器

在浏览器中编辑 SVG 代码,实时预览并下载结果。

文件在浏览器本地处理 • 无需上传服务器 • 可下载最终 SVG。

预览

无文件
上传 SVG 上传后图片会显示在这里,并随代码修改实时更新。
尺寸: — 文件:—

SVG 代码

Живое обновление
0 个字符 修改会自动应用

关于此工具 — 在线 SVG 编辑器

在浏览器中编辑 SVG 代码,实时预览并下载结果。

上传 SVG 文件或粘贴 XML 代码,可修改颜色、尺寸、文字、线条等参数,立即查看效果并保存最终 SVG。 该工具可直接在 DEVNEW.ORG 网页中使用,无需另外安装软件。适合网站站长、开发者、SEO 从业者、设计师以及需要快速在线工具的用户,可免费用于工作和个人任务。

相关推荐

'; empty.style.display = 'none'; frame.style.display = 'block'; setStatusOk(); updateMeta(result.root, source); } function parseAndSanitize(source) { try { const parser = new DOMParser(); const doc = parser.parseFromString(source, 'image/svg+xml'); const parseError = doc.querySelector('parsererror'); if (parseError) { return { ok: false, error: 'SVG 代码存在语法错误。' }; } const root = doc.documentElement; if (!root || root.nodeName.toLowerCase() !== 'svg') { return { ok: false, error: '代码必须包含根 元素。' }; } sanitizeSvg(root); return { ok: true, root: root, svg: new XMLSerializer().serializeToString(root) }; } catch (e) { return { ok: false, error: '无法解析 SVG 代码。' }; } } function sanitizeSvg(root) { const blockedTags = [ 'script', 'foreignObject', 'iframe', 'object', 'embed', 'audio', 'video' ]; blockedTags.forEach(function (tag) { root.querySelectorAll(tag).forEach(function (node) { node.remove(); }); }); root.querySelectorAll('*').forEach(function (node) { Array.from(node.attributes).forEach(function (attr) { const name = attr.name.toLowerCase(); const value = String(attr.value || '').trim().toLowerCase(); if (name.startsWith('on')) { node.removeAttribute(attr.name); return; } if ( (name === 'href' || name === 'xlink:href') && ( value.startsWith('javascript:') || value.startsWith('http://') || value.startsWith('https://') || value.startsWith('//') ) ) { node.removeAttribute(attr.name); } }); }); } function updateMeta(root, source) { let width = root.getAttribute('width') || ''; let height = root.getAttribute('height') || ''; const viewBox = root.getAttribute('viewBox') || ''; if ((!width || !height) && viewBox) { const values = viewBox.trim().split(/\s+/); if (values.length === 4) { if (!width) width = values[2]; if (!height) height = values[3]; } } dimensions.textContent = '尺寸: ' + (width && height ? width + ' × ' + height : '未指定'); const bytes = new Blob([source]).size; fileSize.textContent = 'Файл: ' + formatBytes(bytes); } function clearPreview() { frame.srcdoc = ''; frame.style.display = 'none'; empty.style.display = 'block'; status.className = 'svg-status'; status.innerHTML = ' 无文件'; dimensions.textContent = '尺寸: —'; fileSize.textContent = '文件:—'; chars.textContent = code.value.length + ' 字符'; hideError(); } function setStatusOk() { status.className = 'svg-status ok'; status.innerHTML = ' SVG 有效'; } function setStatusError() { status.className = 'svg-status error'; status.innerHTML = ' Ошибка кода'; } function showError(message) { errorBox.textContent = message; errorBox.style.display = 'block'; } function hideError() { errorBox.textContent = ''; errorBox.style.display = 'none'; } function formatBytes(bytes) { if (bytes >= 1024 * 1024) { return (bytes / 1024 / 1024).toFixed(2) + ' MB'; } if (bytes >= 1024) { return (bytes / 1024).toFixed(2) + ' KB'; } return bytes + ' Б'; } function prettyXml(xml) { xml = xml.replace(/>\s*<'); const nodes = xml.replace(//.test(trimmed)) { pad = Math.max(0, pad - 1); } out += ' '.repeat(pad) + trimmed + '\n'; if ( /^<[^!?/][^>]*[^/]?>$/.test(trimmed) && !/^<(path|circle|rect|line|polyline|polygon|ellipse|use|image|stop|br)\b/i.test(trimmed) && !trimmed.includes('