Closing #5 : preserving transparency in images while converting them to webp

This commit is contained in:
2026-05-11 08:50:28 +02:00
parent fc2e366647
commit f608724968
3 changed files with 3 additions and 3 deletions

View File

@@ -137,7 +137,7 @@ export const handleAvatarUpload = async (req, res) => {
// Convert to webp using ImageMagick with coalesce for GIF handling // Convert to webp using ImageMagick with coalesce for GIF handling
try { try {
await execFile('magick', [tmpPath, '-coalesce', '-resize', '256x256^', '-gravity', 'center', '-extent', '256x256', '-quality', '50', finalPath]); await execFile('magick', [tmpPath, '-coalesce', '-resize', '256x256^', '-gravity', 'center', '-background', 'none', '-extent', '256x256', '-quality', '50', finalPath]);
} catch (err) { } catch (err) {
console.error('[AVATAR HANDLER] Magick error:', err); console.error('[AVATAR HANDLER] Magick error:', err);
await fs.unlink(tmpPath).catch(() => { }); await fs.unlink(tmpPath).catch(() => { });

View File

@@ -101,7 +101,7 @@ export const handleHallImageUpload = async (req, res) => {
// -coalesce is required for animated GIFs: it composites delta frames into full frames // -coalesce is required for animated GIFs: it composites delta frames into full frames
// before resizing, preventing heavy artifacts. Output is animated WebP for GIFs. // before resizing, preventing heavy artifacts. Output is animated WebP for GIFs.
try { try {
await execFile('magick', [tmpPath, '-coalesce', '-resize', '600x300^', '-gravity', 'center', '-extent', '600x300', '-quality', '85', finalPath]); await execFile('magick', [tmpPath, '-coalesce', '-resize', '600x300^', '-gravity', 'center', '-background', 'none', '-extent', '600x300', '-quality', '85', finalPath]);
} catch (err) { } catch (err) {
console.error('[HALL IMG] Magick error:', err.stderr || err.message); console.error('[HALL IMG] Magick error:', err.stderr || err.message);
await fs.unlink(tmpPath).catch(() => {}); await fs.unlink(tmpPath).catch(() => {});

View File

@@ -97,7 +97,7 @@ export const handleUserHallImageUpload = async (req, res, slug) => {
// Resize to 600x300 webp // Resize to 600x300 webp
try { try {
await execFile('magick', [tmpPath, '-coalesce', '-resize', '600x300^', '-gravity', 'center', '-extent', '600x300', '-quality', '85', finalPath]); await execFile('magick', [tmpPath, '-coalesce', '-resize', '600x300^', '-gravity', 'center', '-background', 'none', '-extent', '600x300', '-quality', '85', finalPath]);
} catch (err) { } catch (err) {
console.error('[USER_HALL_IMG] Magick error:', err.stderr || err.message); console.error('[USER_HALL_IMG] Magick error:', err.stderr || err.message);
await fs.unlink(tmpPath).catch(() => {}); await fs.unlink(tmpPath).catch(() => {});