Skip to content

Commit 639683e

Browse files
author
Oscar
committed
reduce screenshot size
1 parent 1340d3f commit 639683e

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,4 @@ vite.config.ts.timestamp-*
141141
.DS_Store
142142
jules-scratch/
143143
jles-scratch/
144+
.seawork/

src/editor/editor.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ import {
1111

1212
const ANNOTATION_STYLE_PREFERENCES_KEY = 'editorAnnotationStylePreferences';
1313
const CLOSE_AFTER_ACTION_KEY = 'editorCloseAfterAction';
14+
const EXPORT_IMAGE_FORMAT = 'jpeg';
15+
const EXPORT_IMAGE_MIME_TYPE = 'image/jpeg';
16+
const EXPORT_IMAGE_QUALITY = 0.85;
17+
const EXPORT_IMAGE_PIXEL_RATIO = 1;
1418
const ANNOTATION_SHAPE_TYPES = new Set(['arrow', 'draw', 'geo', 'highlight', 'line', 'note', 'text']);
1519
const SHARED_ANNOTATION_STYLE_IDS = new Set(['tldraw:color']);
1620

@@ -827,7 +831,8 @@ async function exportAnnotatedScreenshot(format) {
827831
bounds: editorState.bounds,
828832
background: true,
829833
padding: 0,
830-
pixelRatio: Math.max(1, Math.min(2, window.devicePixelRatio || 1)),
834+
pixelRatio: EXPORT_IMAGE_PIXEL_RATIO,
835+
...(format === 'jpeg' ? { quality: EXPORT_IMAGE_QUALITY } : {}),
831836
});
832837

833838
if (!result || !result.blob) {
@@ -841,7 +846,7 @@ async function exportAnnotatedScreenshot(format) {
841846
* @returns {string}
842847
*/
843848
function createScreenshotFilename() {
844-
return `screenshot-${new Date().toISOString().slice(0, 19).replace(/:/g, '-')}.png`;
849+
return `screenshot-${new Date().toISOString().slice(0, 19).replace(/:/g, '-')}.jpg`;
845850
}
846851

847852
/**
@@ -851,8 +856,8 @@ async function copyToClipboard() {
851856
const button = /** @type {HTMLButtonElement | null} */ (document.getElementById('action-copy'));
852857
try {
853858
setButtonBusy(button, true);
854-
const blob = await exportAnnotatedScreenshot('png');
855-
await navigator.clipboard.write([new ClipboardItem({ 'image/png': blob })]);
859+
const blob = await exportAnnotatedScreenshot(EXPORT_IMAGE_FORMAT);
860+
await navigator.clipboard.write([new ClipboardItem({ [EXPORT_IMAGE_MIME_TYPE]: blob })]);
856861
showActionSuccessIcon('action-copy');
857862

858863
if (editorState.closeAfterAction) {
@@ -874,7 +879,7 @@ async function saveImage() {
874879
let objectUrl = '';
875880
try {
876881
setButtonBusy(button, true);
877-
const blob = await exportAnnotatedScreenshot('png');
882+
const blob = await exportAnnotatedScreenshot(EXPORT_IMAGE_FORMAT);
878883
objectUrl = URL.createObjectURL(blob);
879884

880885
const link = document.createElement('a');

0 commit comments

Comments
 (0)