diff options
| author | Yasutake Yohei <61961825+yasutakeyohei@users.noreply.github.com> | 2026-11-01 22:09:07 +0900 |
|---|---|---|
| committer | Yasutake Yohei <61961825+yasutakeyohei@users.noreply.github.com> | 2026-11-01 22:09:07 +0900 |
| commit | 25237779af89ec78deedc63e7f75412bd7d01fde (patch) | |
| tree | 7ba2ef8bbbaddbb59874030e5715907474be6ea6 /public/bluebey-studio/src/main.js | |
| parent | 9a48acc5eeab8f79062dc34a02b5ec292ebdf555 (diff) | |
bluebey: 注意書きに配布の条件を追加し、JPG保存を追加
Diffstat (limited to 'public/bluebey-studio/src/main.js')
| -rw-r--r-- | public/bluebey-studio/src/main.js | 25 |
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; |
