Fix: Sticker Image Decoding and GIF Support#10
Open
moothz wants to merge 1 commit intoEvolutionAPI:mainfrom
Open
Fix: Sticker Image Decoding and GIF Support#10moothz wants to merge 1 commit intoEvolutionAPI:mainfrom
moothz wants to merge 1 commit intoEvolutionAPI:mainfrom
Conversation
Reviewer's GuideAdds GIF and JPEG decoding support and enhances sticker conversion to handle multiple media types (including animated GIFs) via FFmpeg, with optional chroma key transparency for video-based stickers. Sequence diagram for updated sticker sending and media conversionsequenceDiagram
actor Client
participant SendService
participant convertToWebP
participant convertVideoToWebP
participant imageDecode
participant webpEncode
participant ffmpeg
participant HTTPServer
Client->>SendService: SendSticker(stickerData, instance)
SendService->>SendService: validate StickerStruct
alt Sticker is URL (http...)
SendService->>convertToWebP: convertToWebP(imageDataURL, transparentColor)
convertToWebP->>HTTPServer: HTTP GET imageDataURL
HTTPServer-->>convertToWebP: media bytes
convertToWebP->>convertToWebP: mimetype.Detect(data)
alt image/webp
convertToWebP-->>SendService: return original data
else video/mp4 or image/gif
convertToWebP->>convertVideoToWebP: convertVideoToWebP(data, transparentColor)
convertVideoToWebP->>convertVideoToWebP: create temp mp4 file
convertVideoToWebP->>ffmpeg: ffmpeg -i input -vcodec libwebp -filter:v filters ...
ffmpeg-->>convertVideoToWebP: generated webp file
convertVideoToWebP-->>convertToWebP: webp bytes
convertToWebP-->>SendService: webp bytes
else image/jpeg or image/png or image/jpg
convertToWebP->>imageDecode: image.Decode(data)
imageDecode-->>convertToWebP: decoded image.Image
convertToWebP->>webpEncode: webp.Encode(image, options)
webpEncode-->>convertToWebP: webp bytes
convertToWebP-->>SendService: webp bytes
else unsupported format
convertToWebP-->>SendService: error unsupported format
end
else Sticker not URL
SendService->>SendService: handle existing non URL logic
end
SendService-->>Client: MessageSendStruct or error
Class diagram for updated sticker structures and conversion functionsclassDiagram
class StickerStruct {
string Number
string Sticker
string Id
int32 Delay
[]string MentionedJID
bool MentionAll
*bool FormatJid
string TransparentColor
QuotedStruct Quoted
}
class QuotedStruct {
}
class SendService {
SendSticker(data *StickerStruct, instance *Instance) MessageSendStruct
}
class Instance {
}
class MessageSendStruct {
}
class ConversionUtils {
<<utility>>
convertToWebP(imageDataURL string, transparentColor string) []byte, error
convertVideoToWebP(inputData []byte, transparentColor string) []byte, error
}
SendService ..> StickerStruct : uses
SendService ..> Instance : uses
SendService ..> MessageSendStruct : returns
SendService ..> ConversionUtils : calls
StickerStruct --> QuotedStruct : contains
Flow diagram for media-type based WebP conversion with GIF and transparency supportflowchart TD
A[Start convertToWebP] --> B[Fetch URL via HTTP GET]
B --> C[Read response body into bytes]
C --> D[Detect MIME type]
D -->|image_webp| E[Return original data]
D -->|video_mp4 or image_gif| F[Call convertVideoToWebP]
D -->|image_jpeg or image_png or image_jpg| G[Decode image with image.Decode]
D -->|other| Z[Return error unsupported format]
F --> H[Create temp mp4 input file]
H --> I[Build ffmpeg filters
fps=15, scale, pad]
I --> J{TransparentColor set?}
J -->|yes| K[Add colorkey filter with TransparentColor]
J -->|no| L[Use base filters]
K --> M[Run ffmpeg to generate webp]
L --> M[Run ffmpeg to generate webp]
M --> N[Read webp file bytes]
N --> O[Return webp data]
G --> P[Encode to webp with webp.Encode]
P --> Q[Return webp data]
File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The new
convertToWebPhelper useshttp.Getwithout checkingresp.StatusCodeor applying any timeout/context, which can hide upstream errors or hang indefinitely on slow/bad endpoints; consider using anhttp.Clientwith timeouts and validating non-2xx responses before reading the body. - Both
convertToWebPandconvertVideoToWebPread arbitrary remote data into memory and pass it toffmpegwithout any size or duration limits; consider enforcing maximum content length and usingexec.CommandContextwith a timeout to avoid resource exhaustion or long-runningffmpegprocesses.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new `convertToWebP` helper uses `http.Get` without checking `resp.StatusCode` or applying any timeout/context, which can hide upstream errors or hang indefinitely on slow/bad endpoints; consider using an `http.Client` with timeouts and validating non-2xx responses before reading the body.
- Both `convertToWebP` and `convertVideoToWebP` read arbitrary remote data into memory and pass it to `ffmpeg` without any size or duration limits; consider enforcing maximum content length and using `exec.CommandContext` with a timeout to avoid resource exhaustion or long-running `ffmpeg` processes.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes the "failed to decode image: image: unknown format" error by explicitly registering
image/jpegandimage/gifdecoders in the Go environment. Additionally, it updates theconvertToWebPlogic to support GIF images by routing them through the FFmpeg conversion pipeline, enabling both static and animated GIFs to be sent as stickers.These changes have been in effect in my codebase for 3 days now, no other conversion errors popped up while testing.
Related Issue
Closes #5
Type of Change
Testing
Checklist
Summary by Sourcery
Handle additional image formats for sticker conversion and support GIF/video-based stickers via FFmpeg.
Bug Fixes:
Enhancements: