Install latest libvips for image_processing on Heroku
Rails 7 uses libvips instead of ImageMagick as the default variant processor for Active Storage. Heroku doesn't ship with libvips by default, so this post shows how to install it on Heroku.
Make sure you have followed the official upgrade guide to update your application code. The most important setting is to make sure your
config.active_storage.variant_processor like below:
Rails.application.config.active_storage.variant_processor = :vips
Install latest libvips
Run the commands below to add two new buildpacks:
$ heroku buildpacks:add --index 1 https://github.com/heroku/heroku-buildpack-apt
$ heroku buildpacks:add --index 2 https://github.com/brandoncc/heroku-buildpack-vips
And then add this new file to the root directory of your app:
heroku-buildpack-apt allows us to install any packages listed in the
- brandoncc/heroku-buildpack-vips seems to be the most maintained and community-accepted buildpack.
Deploy and Verify
Git add the files and deploy to Heroku. You can verify the result by running this command:
$ heroku run vips -v
vips-8.12.1-Wed Nov 24 15:41:04 UTC 2021
Note that ActiveStorage/image_processing requires libvips 8.6+, which should be no problem if you use brandoncc's buildpack.
I've only tested this on Heroku-18 stack.
- Upgrading Ruby on Rails: Active Storage default variant processor changed to :vips— Ruby on Rails Guides
Add support for libvips · Issue #1200 · heroku/heroku-buildpack-ruby
- Watch this to get notified when Heroku includes libvips in their default Ruby stack.
- Improve libvips support for Heroku? · Issue #32 · janko/image_processing
Clap to support the author, help others find it, and make your opinion count.