Heroku: Running imagemagick with paperclip - ruby-on-rails

I have installed image magick on my mac os x computer and now I want to deploy it to heroku. I've installed the the paperclip plugin on heroku but I get this error when uploading an image:
Paperclip::CommandNotFoundError
I had this error before when I didn't have imagemagick instaledl on my computer before but now that I want to deploy it, how do I get image magick to work on heroku?

Do you have the RMagick gem included in your app on Heroku? It's necessary for interfacing between your Ruby code and ImageMagick.
ImageMagick is part of the Heroku platform by default, but you have to specify that you need the RMagick gem for your app. I'm guessing you have this installed locally so it works there, but it's missing from your Gemfile or gems manifest (depending on Heroku stack version).

Try to remove the Paperclip.options[:command_path] = "/path/to/" when deploying to heroku.
This solved the issue for me.

Add the following to your gemfile...
gem 'rmagick'

Related

Different output wkhtmltopdf local and on heroku

On my Macbook I have wkhtmltopdf installed and when I do wkhtmltopdf -V I get:
wkhtmltopdf 0.12.2.1 (with patched qt)
When I deploy the Rails app to Heroku, the PDF renders different. So I checked the version on Heroku with heroku run "wkhtmltopdf -V", but that gives me:
bash: wkhtmltopdf: command not found.
The PDF itself renders fine on Heroku, so there must be a wkhtmltopdf installed I guess? I followed these instructions to create a buildpack, but with no change when I request the version:
https://elements.heroku.com/buildpacks/rafaelp/heroku-buildpack-wkhtmltopdf
In the Gemfile I have this:
group :development do
gem 'wkhtmltopdf-binary-edge', '~> 0.12.2.1'
end
So, how do I properly install wkhtmltopdf on Heroku and make sure the version is the same as on my Macbook?
You're probably seeing a conflict in versions here between a binary bundled in the gem you're using in development, and another binary.
You should manually manage your wkhtmltopdf binary manually in development & heroku (homebrew/apt-get + buildpack), or use a gem which includes the binaries in both environments. Not a mix of both, as you'll get inconsistent results.
Personally, I use this buildpack on heroku and use brew to install the version I need locally for development.

Where are Ruby gems located on a server?

My understanding is that the gemfile in a Rails app only provides references to the actual code of these gems on your local computer. So when you're running your app locally, it's pulling the gem code from your local computer. What happens when you deploy though? The server runs your rails code, but does it also hold all the references in your gem file and automatically download them as well?
Yep. If you deploy on Heroku, you can see bundler doing its work and pulling down the gems.
As per the Bundler docs, you can use bundle show --paths to see exactly where your gems are being loaded from.
Additionally, if you aren't using bundler, you can use the command gem environment to see gem paths on the system.
See this existing answer for more info: How can I find where gem files are installed?

Rails Error on Windows: ImageMagick/GraphicsMagick is not installed

I get this error when i ran my rails app on my Windows Localhost when I tried to upload an image.
I have a "product" model and I am using Mini_Magick with CarrierWave for uploading the product's image.
Image Failed to manipulate with MiniMagick, maybe it is not an image? Original Error: ImageMagick/GraphicsMagick is not installed
I have done the "bundle install" command after putting mini_magick gem in my gem-file and I have checked that Imagemagick is installed by running "convert" everything works fine... What could be the problem?
Have you installed GraphicsMagick on your machine? You will need this installed locally if your doing any kind of image manipulation with your uploads, which it appears you are.
Downloads can be found here:
ftp://ftp.graphicsmagick.org/pub/GraphicsMagick/windows/
Another advise: this error happened to me even after installing GraphicsMagick, I solved it by restarting visual studio code, which is the IDE I'm using. So, be ware of restarting the terminal you are using to run rails after installing GraphicsMagick

RMagick: Must specify image size (in Heroku)

I managed to run this line in development with no problem:
canvas = Magick::Image.read("caption:#{something}")
But deploying in Heroku, this message appears:
Magick::ImageMagickError (must specify image size `something?' # error/caption.c/ReadCAPTIONImage/135)
Is there any way to proceed without providing image dimensions? I need to these image files with text on the fly and I can't provide an exact width.
Thank you
You are most likely having a compatibility issue between rMagick and ImageMagick (which rMagick uses). I had the reverse problem: reading images suddenly didn't work locally, but worked fine on production.
I just read that Heroku is using a very old version of ImageMagick (6.5, but that may have changed.) I would try downgrading the version of rMagick you are using by setting it in your Gemfile. I'm using v 2.13.3.
gem "rmagick", "2.13.3", :require => "RMagick"

Ruby on Rails Avatar Paperclip::CommandNotFoundError

I've been trying to work with Paperclip. I've installed ImageMagick. I've added the line
Paperclip.options[:command_path] = "/usr/local/bin" in config/initializers/paperclip.rb.
But i'm still getting the error "Avatar Paperclip::CommandNotFoundError".
How can i possibly solve this?
First, make sure you have the rmagick gem in your Gemfile
gem 'rmagick', :require => 'RMagick'
Next, open a rails console from the command line.
$ rails c
type:
`which convert`
You should see something like
=> "/usr/bin/convert\n"
If you do, then take the path, in this case /usr/bin, and set Paperclip.options[:command_path] to that path. If you don't, you need to make sure that ImageMagick is installed. For OSX use Homebrew (http://mxcl.github.com/homebrew/) or MacPorts. For Debian systems you'll need two packages:
imagemagick
libmagick9-dev
For Redhat/rpm-based systems, you can try their packages, but they are pretty old and you'll probably be better off compiling from source.
If you've got ImageMagick already installed then you'll need to make sure the convert command is in your path.
As a side note, if the rmagick gem installs, then you should have ImageMagick already installed, you just need to figure out where it is on your system.
have you tried installing/using rMagic?
I installed ImageMagick using the Binary from Macports for Snow Leopard. The install went fine, but Paperclip wasn't finding ImageMagick and I was getting the same errors.
I added the following to config/environments/development.rb:
Paperclip.options[:command_path] = "/opt/local/bin"
I restarted the server and everything works perfectly.

Resources