Repository navigation
Fix image blur not applying on mobile browsers - #10
Merged
Merged
Conversation
Canvas ctx.filter blur() is silently ignored by iOS Safari (and unreliable on other WebKit builds), so the uploaded photo's blur slider had no visible effect on mobile. Replace it with a downsample-then-upsample technique using only drawImage, which works reliably everywhere.
|
The downsample-then-upsample approximation looked mushy/blocky compared to the original ctx.filter blur. Replace it with a triple-pass box blur on pixel data (the standard cheap Gaussian approximation), which gives a much closer match to how blur looked on desktop, while still avoiding ctx.filter for mobile reliability. Working resolution is capped so cost stays bounded even at large export sizes.
Swap the custom triple-pass box blur for stackblur-canvas, a small, well-tested library that implements the same near-Gaussian blur technique with correct alpha handling, removing ~90 lines of fiddly custom pixel-manipulation code.
It was only used once, right after being computed.
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
ctx.filter = "blur(...)"is silently ignored by iOS Safari (and unreliable on other WebKit builds), so the uploaded photo's Blur slider had no visible effect on mobile.drawImage/imageSmoothingEnabled, which is reliable on every browser.<feGaussianBlur>) and is untouched.