Skip to content

Commit d911c2c

Browse files
committed
Various fixes to SVG tool
Tweaked CSS Selecting transparent now toggles to PNG Copy to clipboard button no longer uses alert()
1 parent c0608a8 commit d911c2c

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

svg-render.html

+23-11
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,20 @@
2121
border: 2px dashed #ccc;
2222
border-radius: 5px;
2323
padding: 10px;
24-
margin-bottom: 10px;
24+
margin: 10px 0;
2525
position: relative;
26+
box-sizing: border-box;
2627
}
2728
#dropZone.dragover {
2829
border-color: #000;
2930
background-color: #f0f0f0;
3031
}
3132
#svgInput {
32-
width: 90%;
33-
height: 10em;
33+
width: 100%;
34+
height: 100%;
3435
border: none;
36+
resize: none;
37+
box-sizing: border-box;
3538
}
3639
#imageContainer {
3740
margin-top: 20px;
@@ -46,8 +49,8 @@
4649
max-width: unset;
4750
}
4851
#base64Output {
49-
overflow-wrap: break-word;
5052
word-break: break-all;
53+
white-space: pre-wrap;
5154
}
5255
.option-group {
5356
margin-bottom: 10px;
@@ -83,14 +86,14 @@ <h1>SVG to Image Converter</h1>
8386
<input type="radio" name="format" value="image/jpeg" checked> JPEG
8487
</label>
8588
<label>
86-
<input type="radio" name="format" value="image/png"> PNG
89+
<input id="pngRadio" type="radio" name="format" value="image/png"> PNG
8790
</label>
8891
</div>
8992
<div class="option-group">
9093
<label for="bgColor">Background Color:</label>
9194
<input type="color" id="bgColor" value="#ffffff">
9295
<label>
93-
<input type="checkbox" id="transparentBg" checked> Transparent
96+
<input type="checkbox" id="transparentBg"> Transparent
9497
</label>
9598
</div>
9699
<div class="option-group">
@@ -101,10 +104,11 @@ <h1>SVG to Image Converter</h1>
101104
<div id="imageContainer"></div>
102105
<a id="downloadLink" style="display: none;">Download Image</a>
103106
<span id="fileSize"></span>
104-
<h2>Base64 Image Tag:</h2>
105-
<pre id="base64Output"></pre>
106-
<button onclick="copyBase64Tag()">Copy Image Tag</button>
107-
107+
<div id="output" style="display: none;">
108+
<h2>Base64 Image Tag:</h2>
109+
<button id="copyImageButton" onclick="copyBase64Tag()">Copy image tag</button>
110+
<pre id="base64Output"></pre>
111+
</div>
108112
<script>
109113
const dropZone = document.getElementById('dropZone');
110114
const svgInput = document.getElementById('svgInput');
@@ -114,6 +118,8 @@ <h2>Base64 Image Tag:</h2>
114118
const bgColor = document.getElementById('bgColor');
115119
const transparentBg = document.getElementById('transparentBg');
116120
const fileSizeSpan = document.getElementById('fileSize');
121+
const outputDiv = document.getElementById('output');
122+
const copyImageButton = document.getElementById('copyImageButton');
117123

118124
// Load example image functionality
119125
loadExampleLink.addEventListener('click', (e) => {
@@ -138,6 +144,7 @@ <h2>Base64 Image Tag:</h2>
138144
transparentBg.addEventListener('change', () => {
139145
if (transparentBg.checked) {
140146
bgColor.value = "#ffffff";
147+
pngRadio.click();
141148
}
142149
});
143150

@@ -264,6 +271,7 @@ <h2>Base64 Image Tag:</h2>
264271
// Display base64 image tag
265272
const imgTag = `<img src="${imageDataUrl}" alt="Converted ${format === 'image/jpeg' ? 'JPEG' : 'PNG'}" width="${newWidth}" height="${newHeight}">`;
266273
base64Output.textContent = imgTag;
274+
outputDiv.style.display = 'block';
267275
};
268276
img.src = svgUrl;
269277
}
@@ -281,7 +289,11 @@ <h2>Base64 Image Tag:</h2>
281289
window.getSelection().addRange(range);
282290
document.execCommand('copy');
283291
window.getSelection().removeAllRanges();
284-
alert('Image tag copied to clipboard!');
292+
const origText = copyImageButton.innerText;
293+
copyImageButton.innerText = 'Copied to clipboard';
294+
setTimeout(() => {
295+
copyImageButton.innerText = origText;
296+
}, 2000);
285297
}
286298
</script>
287299
</body>

0 commit comments

Comments
 (0)