fix(send): generate JPEGThumbnail for PDF documents sent via /send/media#84
Open
fernandopaes0 wants to merge 3 commits into
Open
fix(send): generate JPEGThumbnail for PDF documents sent via /send/media#84fernandopaes0 wants to merge 3 commits into
fernandopaes0 wants to merge 3 commits into
Conversation
Images sent through SendMediaFile and SendMediaUrl were delivered without a JPEGThumbnail, so clients (notably iOS) showed no inline preview until the full image finished downloading. This adds a reusable makeJPEGThumbnail helper that decodes the source bytes, resizes to a 72px-wide preview preserving aspect ratio (never upscaling), and JPEG-encodes it at quality 50. The helper is wired into the image branch of both SendMediaFile and SendMediaUrl (newsletter and normal paths). The existing inline thumbnail logic in SendCarousel is refactored to reuse the same helper. Thumbnail generation is best-effort: if decoding or encoding fails the helper returns nil and the message is sent without a preview rather than failing the request. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
PDF documents sent through SendMediaFile and SendMediaUrl had no inline preview thumbnail, so clients showed a generic document icon instead of a preview of the first page. This adds a makePDFThumbnail helper that rasterizes page 1 of the PDF with the external pdftoppm tool (poppler-utils) and re-encodes the result through makeJPEGThumbnail for a consistent preview. The thumbnail is wired into the document branch of both SendMediaFile and SendMediaUrl when the detected mime type is application/pdf. The feature degrades gracefully: if pdftoppm is not installed or rasterization fails, the helper returns nil and the document is sent without a preview rather than panicking or returning an error. Note: poppler-utils must be available in the runtime image for this to take effect (see Dockerfile). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds a custom Dockerfile that mirrors the upstream build and installs poppler-utils (pdftoppm) in the runtime image, which is required for the PDF document thumbnail feature. Kept separate from the upstream Dockerfile. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Sorry @fernandopaes0, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
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.
Problem
PDF documents sent via
/send/mediashow no preview thumbnail in WhatsApp — the recipient sees a generic document icon.Solution
Added a
makePDFThumbnailhelper that rasterizes the first page of the PDF usingpdftoppm(poppler-utils) at 200px width, then encodes the result as JPEG viamakeJPEGThumbnail.poppler-utilsinstalled on the host (or Docker image)pdftoppmis unavailable or PDF is invalid, returnsniland send proceeds normallyDockerfile note
If using the official Docker image, add to your Dockerfile:
RUN apt-get update && apt-get install -y poppler-utils && rm -rf /var/lib/apt/lists/*Testing
Unit tests added in
pkg/sendMessage/service/thumbnail_test.go:pdftoppmnot present in CI)