You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix JPEG variants uploaded as .jfif, .jif or .jfi - #103
Rails names a web image's variant format after the upload's extension when Marcel maps that extension to the blob's content type (representable.rb#L180-L186). So a JPEG uploaded as photo.jfif asks the cell for format jfif, and the transformers fail on some of these formats:
transformers.image.vips fails .jif and .jfi with No known saver for 'jif'. libvips has a saver for .jfif but not for .jif or .jfi. Stock Rails on vips fails the same way.
Transforming#process in activestorage-hotcell-client now sends the cell the canonical extension of the format's content type, Marcel::Magic.new(content_type).extensions.first. Rails falls back to the same extension when the upload's extension does not match. The change applies only to formats whose content type is in ActiveStorage.web_image_content_types, because Rails takes a format from the filename only for those types. Every other format crosses unchanged.
The variant's format in Rails is unchanged, so variation keys and variant URLs stay the same.
Additional information
This is an alternative to #101, which stages the ImageMagick output under the format's extension and renames it into place. Here, #82's direct write and image_processing's format check stay, and the Vips transformer is fixed too.
An application that calls active_storage.transformers.image.magick directly with jfif, without this gem's client, still gets unreadable.
Since #82, the ImageMagick transformer failed a JPEG uploaded as .jfif,
.jif or .jfi permanently as `unreadable`. The Vips transformer has
always failed .jif and .jfi the same way. Send the cell the canonical
extension of a web image format's content type, which is the extension
Rails falls back to when an upload's extension does not match.
[Fix#84]
Canonicalizes Rails web-image format aliases before sending transformations to the cell.
Changes:
Maps JPEG aliases such as jfif, jif, and jfi to jpg.
Adds ImageMagick and Vips regression tests.
Documents the fix in the changelog.
[!TIP]
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
This changes the wire format before the Vips operation receives it, so the existing contract comment in activestorage-hotcell-server/lib/active_storage/hot_cell/server/transformers/image/vips.rb:11-13 is now false: the format no longer reaches ImageProcessing exactly as Rails supplied it. Please update that comment to document the canonicalization exception.
The comment said the format reached ImageProcessing exactly as Rails
handed it over, which stopped being true when the client began sending
a web image's canonical extension.
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
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.
Motivation
Rails names a web image's variant format after the upload's extension when Marcel maps that extension to the blob's content type (
representable.rb#L180-L186). So a JPEG uploaded asphoto.jfifasks the cell for formatjfif, and the transformers fail on some of these formats:transformers.image.magickfails.jfif,.jifand.jfipermanently asunreadable. Since Require image_processing 2.2.0 and drop the transform rename #82 it saves tojfif:/scratch/output-0, and ImageMagick has no coder by that name (transformers.image.magickfails a.jfifupload with MiniMagick::Error "unable to open image 'jfif:...'" #84).transformers.image.vipsfails.jifand.jfiwithNo known saver for 'jif'. libvips has a saver for.jfifbut not for.jifor.jfi. Stock Rails on vips fails the same way.Fixes #84
Details
Transforming#processinactivestorage-hotcell-clientnow sends the cell the canonical extension of the format's content type,Marcel::Magic.new(content_type).extensions.first. Rails falls back to the same extension when the upload's extension does not match. The change applies only to formats whose content type is inActiveStorage.web_image_content_types, because Rails takes a format from the filename only for those types. Every other format crosses unchanged.The variant's format in Rails is unchanged, so variation keys and variant URLs stay the same.
Additional information
This is an alternative to #101, which stages the ImageMagick output under the format's extension and renames it into place. Here, #82's direct write and image_processing's format check stay, and the Vips transformer is fixed too.
An application that calls
active_storage.transformers.image.magickdirectly withjfif, without this gem's client, still getsunreadable.