Skip to content

Transform a JPEG uploaded as .jfif with the ImageMagick transformer - #101

Closed
robzolkos wants to merge 2 commits into
masterfrom
fix/magick-format-extension
Closed

robzolkos wants to merge 2 commits into
masterfrom
fix/magick-format-extension

Conversation

@robzolkos

Copy link
Copy Markdown

Fixes #84

Why

Rails names a web image's variant format after the upload's extension when Marcel maps that extension to the blob's content type. So an app using the ImageMagick transformer gets format jfif for a JPEG uploaded as photo.jfif. The same goes for .jif and .jfi, in any letter case.

Since #82, the transform saves straight to the output's scratch path, which has no extension, so image_processing names the output format with a prefix: jfif:/…/output-0. ImageMagick has no coder called JFIF. It reads the whole string as a filename, fails to open it, and the operation answers unreadable, a permanent failure, for a perfectly good JPEG. Stock Rails doesn't hit this, because it lets image_processing name a tempfile with the extension.

What changes

  • The ImageMagick toolchain stages its output on a sibling named with the format's extension (Output#path(extension:)) and adopts it into place, as it did before Require image_processing 2.2.0 and drop the transform rename #82. ImageMagick picks the coder from an extension it knows, and keeps the source's format for one it doesn't. That's the same thing stock Rails gets.
  • The Vips toolchain keeps Require image_processing 2.2.0 and drop the transform rename #82's direct write and its saved rename. Transforming#perform names the save path through a new encoded_path hook: the default is the scratch path, and Transformers::Image::Magick overrides it.
  • Docs and changelog: the Output#path doc and comment now mention this second use of the extension sibling, and there's a changelog entry under ActiveStorage::HotCell::Server / Fixed.

An explicit svgz variant, which failed the same way, now behaves as it does under stock Rails too.

Tests

magick_transform_image_test.rb gets #84's reproduction for jfif, jif and jfi: a JPEG transformed to each format comes back as a resized JPEG.

  • These are committed on their own first, in 54e9109, and fail on that commit with unable to open image 'jfif:…'.
  • They pass with the fix.

bundle exec rake passes locally: every suite including test:activestorage, plus rubocop. rake docs:check is clean.

Rails names a web image's variant format after its upload's extension, so
a JPEG uploaded as .jfif, .jif or .jfi asks for that format. Since #82 the
ImageMagick transform writes `jfif:/scratch/output-0`, and ImageMagick has
no coder by that name, so it fails as unreadable. Refs #84.
Since #82 the transform has written `format:/scratch/output-0`, and
ImageMagick reads a prefix it has no coder for as part of the filename, so
a JPEG uploaded as .jfif, .jif or .jfi failed as unreadable. The ImageMagick
toolchain stages a sibling named with the format's extension again and
adopts it into place, as before #82, so an unknown format keeps the
source's, as it does under stock Rails. The vips toolchain keeps #82's
direct write. Fixes #84.
Copilot AI balanced review requested due to automatic review settings October 7, 2026 19:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@flavorjones

Copy link
Copy Markdown
Member

Going to decline to merge in favor of hotcell#103 which modifies the format on the client side. I think that's cleaner and also improves the VIPS side of the house.

@flavorjones flavorjones closed this Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

transformers.image.magick fails a .jfif upload with MiniMagick::Error "unable to open image 'jfif:...'"

3 participants