Improve JPEG output quality
- Live camera: 0.92 -> 0.97 quality - Library upload: 0.92 -> 0.97 starting quality - Size limit: 10MB -> 20MB before compression kicks in - Gentler quality steps: drops by 0.03 instead of 0.1 - Higher quality floor: 0.50 instead of 0.30 - Gentler downscaling: 0.85x instead of 0.8x per step Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -509,7 +509,7 @@ async function takePhoto() {
|
||||
setTimeout(() => flash.classList.remove('flash'), 150);
|
||||
|
||||
const blob = await new Promise((resolve, reject) => {
|
||||
canvas.toBlob(b => b ? resolve(b) : reject(new Error('Canvas capture failed')), 'image/jpeg', 0.92);
|
||||
canvas.toBlob(b => b ? resolve(b) : reject(new Error('Canvas capture failed')), 'image/jpeg', 0.97);
|
||||
});
|
||||
|
||||
await savePhoto(blob);
|
||||
@@ -571,7 +571,7 @@ async function savePhoto(jpegBlob) {
|
||||
}
|
||||
}
|
||||
|
||||
const MAX_UPLOAD_BYTES = 10 * 1024 * 1024;
|
||||
const MAX_UPLOAD_BYTES = 20 * 1024 * 1024;
|
||||
|
||||
function convertToJPEG(file) {
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -579,7 +579,7 @@ function convertToJPEG(file) {
|
||||
reader.onload = (e) => {
|
||||
const img = new Image();
|
||||
img.onload = () => {
|
||||
let quality = 0.92;
|
||||
let quality = 0.97;
|
||||
let scale = 1.0;
|
||||
|
||||
const attempt = () => {
|
||||
@@ -593,14 +593,14 @@ function convertToJPEG(file) {
|
||||
reject(new Error('Failed to convert'));
|
||||
return;
|
||||
}
|
||||
if (blob.size <= MAX_UPLOAD_BYTES || quality <= 0.3) {
|
||||
if (blob.size <= MAX_UPLOAD_BYTES || quality <= 0.5) {
|
||||
resolve(blob);
|
||||
} else {
|
||||
if (quality > 0.5) {
|
||||
quality -= 0.1;
|
||||
if (quality > 0.85) {
|
||||
quality -= 0.03;
|
||||
} else {
|
||||
scale *= 0.8;
|
||||
quality = 0.7;
|
||||
scale *= 0.85;
|
||||
quality = 0.92;
|
||||
}
|
||||
attempt();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user