Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@robbyczgw-cla
Copy link
Contributor

@robbyczgw-cla robbyczgw-cla commented Jan 23, 2026

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

  • Added hasAlphaChannel() function to detect PNG files with alpha channel
  • Added resizeToPng() function for PNG-specific image resizing
  • Added optimizeImageToPng() function to preserve PNG transparency
  • Modified src/web/media.ts to detect PNG with alpha and route to PNG optimization

Fixes #1473


🤖 AI-Assisted Development

Tool: Claude (Opus 4.5) via Clawdbot

Testing: Lightly tested

  • tsc --noEmit passes ✅
  • No runtime tests yet

Prompts/Session:
User asked to fix issue #1473. After analyzing the codebase:

  1. Found loadWebMedia() in src/web/media.ts routes all images through optimizeImageToJpeg()
  2. JPEG doesn't support alpha → transparency lost
  3. Solution: detect PNG+alpha via sharp metadata, route to new PNG optimizer

Understanding: Yes ✅

  • hasAlphaChannel(): Uses sharp's metadata().hasAlpha or channels === 4 to detect transparency
  • resizeToPng(): Resizes with .png({ compressionLevel }) instead of .jpeg()
  • optimizeImageToPng(): Grid search over sizes/compression levels (like JPEG version)
  • Integration: Check isPng && hasAlpha before optimization, route accordingly

@steipete steipete self-assigned this Jan 23, 2026
@steipete steipete merged commit e634791 into openclaw:main Jan 23, 2026
20 of 22 checks passed
@steipete
Copy link
Contributor

Landed via temp rebase onto main.

Thanks @robbyczgw-cla!

@naari3
Copy link

naari3 commented Jan 26, 2026

thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Discord - Transparent PNG loses alpha channel when sent via message tool

3 participants