aboutsummaryrefslogtreecommitdiffhomepage
path: root/public/bluebey-studio/src/main.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/bluebey-studio/src/main.js')
-rw-r--r--public/bluebey-studio/src/main.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/public/bluebey-studio/src/main.js b/public/bluebey-studio/src/main.js
index 57f0140..fcee21d 100644
--- a/public/bluebey-studio/src/main.js
+++ b/public/bluebey-studio/src/main.js
@@ -1317,6 +1317,7 @@ async function init() {
syncPanel: () => app.panel?.sync(),
imageCanvas: (options) => captureImage(options),
savePNG: (options = {}) => savePNG(options),
+ saveJPG: (options = {}) => saveJPG(options),
copyPNG: () => copyPNG(),
addGionStamp: (item) => addGionStamp(item),
saveSettings: () => exporter.downloadText(JSON.stringify(state, null, 2), `bluebey-settings-${exporter.timestamp()}.json`),
@@ -2060,6 +2061,30 @@ async function init() {
toast(`PNGを書き出しました(${result.width}×${result.height})`);
}
+ /**
+ * JPEG: the small-file export. JPEG has no alpha, so the picture is laid on the
+ * paper colour first - a transparent background would otherwise come out black.
+ * A photo backdrop is kept at the chosen scale/quality, which makes the file a
+ * fraction of the same PNG.
+ */
+ async function saveJPG({
+ scale = state.render.pngScale ?? 2,
+ quality = state.render.jpgQuality ?? 0.9,
+ } = {}) {
+ const result = await captureImage({ scale, transparent: false });
+ const out = document.createElement('canvas');
+ out.width = result.width;
+ out.height = result.height;
+ const ctx = out.getContext('2d');
+ ctx.fillStyle = state.render.paper || '#ffffff';
+ ctx.fillRect(0, 0, out.width, out.height);
+ ctx.drawImage(result.canvas, 0, 0);
+ const blob = await new Promise((resolve) => out.toBlob(resolve, 'image/jpeg', quality));
+ exporter.downloadBlob(blob, `bluebey-${exporter.timestamp()}.jpg`);
+ toast(`JPGを書き出しました(${result.width}×${result.height}・画質${Math.round(quality * 100)}%)`);
+ return { blob, width: result.width, height: result.height, quality };
+ }
+
/** Hide the gizmo and helpers so they never end up in an export. */
async function withHiddenHelpers(fn) {
const wasVisible = rig.helper.visible;