First, on Heroku, you’ll need to add a special buildpack to your slug:

(note that all of the following commands you may need to append with -a if you manage more than one Heroku app)

heroku buildpacks:add -i 1 https://github.com/jasonfb/heroku-buildpack-cedar14-imagemagick695

(Here -i 1 tells the command you want the buildpack at index 1. It’s important that you include this flag or else the Heroku API will add your buildpack before the default build, which is known simply as heroku/ruby)

(If you’d prefer to use ImageMagick 7.0.24, I’ve also made a buildpack for that available here: https://github.com/jasonfb/heroku-buildpack-cedar14-imagemagick704)

You can and should examine what you just added with:

To examine what you just did:

heroku buildpacks

You should see the response:

$ heroku buildpacks:add -i 1 https://github.com/jasonfb/heroku-buildpack-imagemagick695

Buildpack added. Next release on app-xyz will use:
 1. https://github.com/jasonfb/heroku-buildpack-imagemagick695
 2. heroku/ruby
Run git push heroku master to create a new release using these buildpacks.

To undo what you just did

heroku buildpacks:remove https://github.com/jasonfb/heroku-buildpack-imagemagick695

Then push your app to your repo. You will notice it takes a few minutes to compile the new ImageMagick binary and install it into the slug.

You can set the :convert_options in your paperclip definitions, or to make a global change to all your definitions use a monkeypatch like so:

Create a file for paperclip init if you don’t already have one

config/initializers/paperclip_defaults.rb

Monkeypatch the Paperclip processor with the resize filter of your choice.

module Paperclip
 class Processor
def convert(arguments = “”, local_options = {})
 if (arguments =~ /-resize/)
  arguments.sub!(“-resize”, “-filter Lanczos -resize”)
 end
 Paperclip.run(‘convert’, arguments, local_options)
end
 end
end

You can read all about the kinds of filters here.

By Jason

Leave a Reply

Your email address will not be published. Required fields are marked *