Dragonfly Gem with ImageMagick and Passenger

2019-07-21 05:16发布

I was having some problems getting the dragonfly gem to play nicely with passenger. Passenger doesn't seem to use the current $PATH so it can't find the convert binary. I've added some configuration to dragonfly which seems to solve the issue:

require 'dragonfly/rails/images'

Dragonfly[:images].configure do |c|
  c.convert_command  = "/usr/local/bin/convert" # defaults to "convert"
  c.identify_command = "/usr/local/bin/convert" # defaults to "convert"
end

but the gem i'm working on is going to be used as an engine and it's going to be a real pain to have to manually set the location to the imagemagick utilities for each install if passenger is used, is there a better solution to automatically specify the location to convert if available?

1条回答
冷血范
2楼-- · 2019-07-21 05:23

Hey mario, try something like this. I've been using it to resolve pathing problems with passenger+paperclip+rmagick.

path = `which convert`.strip.gsub('convert','').presence || "/usr/local/bin/"

It should return /usr/local/bin when convert isn't in the path or unable to be found.

查看更多
登录 后发表回答