Skip to content

Commit fa5a395

Browse files
authored
Added paste support
curl 'https://tools.simonwillison.net/image-resize-quality' | llm -m claude-3.5-sonnet --system 'output just the new HTML for a version of this page that also allows users to paste images'
1 parent 0e440ad commit fa5a395

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

image-resize-quality.html

+15-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<body>
5252
<h1>Image resize and quality comparison</h1>
5353
<div id="drop-zone">
54-
<p>Drop an image here or click to select</p>
54+
<p>Drop an image here, click to select, or paste an image</p>
5555
</div>
5656
<input type="file" id="file-input" accept="image/*" style="display: none;">
5757
<div id="output"></div>
@@ -70,6 +70,9 @@ <h1>Image resize and quality comparison</h1>
7070
dropZone.addEventListener('drop', handleDrop);
7171
fileInput.addEventListener('change', (e) => handleFile(e.target.files[0]));
7272

73+
// Add paste event listener to the document
74+
document.addEventListener('paste', handlePaste);
75+
7376
function handleDrop(e) {
7477
e.preventDefault();
7578
dropZone.classList.remove('dragover');
@@ -89,6 +92,17 @@ <h1>Image resize and quality comparison</h1>
8992
reader.readAsDataURL(file);
9093
}
9194

95+
function handlePaste(e) {
96+
const items = e.clipboardData.items;
97+
for (let i = 0; i < items.length; i++) {
98+
if (items[i].type.indexOf('image') !== -1) {
99+
const blob = items[i].getAsFile();
100+
handleFile(blob);
101+
break;
102+
}
103+
}
104+
}
105+
92106
function processImage(img) {
93107
output.innerHTML = '';
94108
const qualities = [1, 0.9, 0.7, 0.5, 0.3];

0 commit comments

Comments
 (0)