ActiveStorage::InvariableError in Home#index

Viewed 4198

Currently I'm trying to display .HEIC images in Rails 6. I'm using ActiveStorage ImageMagic to use variant to display jpg. Basically I'm trying to use

mogrify -format jpg myimage.heic

In the image to display jpg.

I added Rails.application.config.active_storage.variant_processor into application.rb to be able to use the variant. However it seems to break in the following line:

 <%= image_tag post.image.variant(format: 'jpg'), class: "card-home__img" %>

Why is not working?

2 Answers

You can only call variant on an image that returns true when you call variable? on it.

Internally, ActiveStorage checks if ActiveStorage.variable_content_types contains your image's type. The default supported values are:

  • image/png
  • image/gif
  • image/jpg
  • image/jpeg
  • image/pjpeg
  • image/tiff
  • image/bmp
  • image/vnd.adobe.photoshop
  • image/vnd.microsoft.icon
  • image/webp

So it seems that currently .HEIC images are not supported.

You can instead apply a format transformation before attaching the image to a model or storing it, it might solve your use case.

Related