fix(media): preserve alpha channel for transparent PNGs #1491
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
PNG images with transparency were being converted to JPEG format when sent via the message tool to Discord, which strips the alpha channel and loses transparency.
Solution
Detect PNG images that have an alpha channel and use PNG optimization instead of JPEG compression, preserving the transparency.
Changes
hasAlphaChannel()function to detect PNG files with alpha channelresizeToPng()function for PNG-specific image resizingoptimizeImageToPng()function to preserve PNG transparencysrc/web/media.tsto detect PNG with alpha and route to PNG optimizationFixes #1473
🤖 AI-Assisted Development
Tool: Claude (Opus 4.5) via Clawdbot
Testing: Lightly tested
tsc --noEmitpasses ✅Prompts/Session:
User asked to fix issue #1473. After analyzing the codebase:
loadWebMedia()insrc/web/media.tsroutes all images throughoptimizeImageToJpeg()Understanding: Yes ✅
hasAlphaChannel(): Uses sharp'smetadata().hasAlphaorchannels === 4to detect transparencyresizeToPng(): Resizes with.png({ compressionLevel })instead of.jpeg()optimizeImageToPng(): Grid search over sizes/compression levels (like JPEG version)isPng && hasAlphabefore optimization, route accordingly