Accept SVG marker uploads via cairosvg rasterisation (#804)#945
Open
vjpixel wants to merge 1 commit into
Open
Conversation
Marker.source is an ImageField, so its form-level validation delegated to Pillow — and Pillow can't open SVG. Anyone trying to upload an SVG hit "Upload a valid image" before any of our own code ran. Override UploadMarkerForm.source as a plain FileField so the ImageField check is bypassed, and validate ourselves in clean_source: - For .svg, rasterise to PNG via cairosvg at 1024 px wide and hand the rest of the pipeline (pymarker, storage) the PNG. - For everything else, run Pillow's own verify() to reject non-images with our own message. Verified manually: - SVG (rect 100x100) → cleaned file is test.png, 3147 bytes - JPG → accepted unchanged - PDF → rejected with "Upload a valid image" Adds: - cairosvg ~2.7 to project dependencies - libcairo2 to the Dockerfile base apt-get install (cairosvg needs libcairo at runtime) JPG support was already working (Pillow opens JPG natively); the issue's main blocker was SVG. Closes #804 https://claude.ai/code/session_01XC1THLWgnGXGf5wgRhdyvB
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.
Summary
Marker.sourceis a DjangoImageField, so its form-level validation delegated to Pillow — and Pillow can't open SVG. Any user trying to upload an SVG hit "Upload a valid image" before any of our own code ran.Override
UploadMarkerForm.sourcewith a plainFileFieldso the strict ImageField check is bypassed, and run our own validation inclean_source:cairosvgat 1024 px width and hand the rest of the pipeline (pymarker, storage) the PNG.verify()to reject non-image uploads with our own message.JPG was already accepted (Pillow opens JPG natively) — the issue's main practical blocker was SVG.
Verified locally
test.svg(rect 100×100)test.png, 3147 bytestest.jpgfoo.pdfDependencies
cairosvg ~= 2.7added topyproject.toml.libcairo2added to the Dockerfile's baseapt-get install(cairosvg needs libcairo at runtime).Test plan
Closes #804
https://claude.ai/code/session_01XC1THLWgnGXGf5wgRhdyvB
Generated by Claude Code