Heroku: Running imagemagick with paperclip
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).
Paperclip w/ Imagemagick, Amazon S3 and Heroku - Imagemagick & S3 work, but the Paperclip fields don't get set in database. Works fine in dev
I think the problem is that you have specified attr_accessor for the paperclip attributes. That is not needed. I actually got the same problem as you when I added those lines to my model. So it should be enough to remove those lines.
Understanding Server Set-up for Using ImageMagick and PaperClip with Ruby on Rails
The simple answer (I couldn't bring myself to read your prose) is to realize that Rails runs on Ruby, which means it harnesses the gem
system of the language
When you install gems, there are two things you have to consider. Firstly, most gems are "internal" to Ruby only; meaning they will provide functionality for API's or something programmatic; The second bunch of gems work with third party software - such as MYSQL or ImageMagick
When you use a gem which interfaces with other software, that software needs to be installed (so the gem can use it). This is where the problems start to occur for many people using ImageMagick
--
Paperclip
You must remember that Paperclip
is not dependent on ImageMagick to run
From the Paperclip github repo:
Paperclip is intended as an easy file attachment library for Active
Record. The intent behind it was to keep setup as easy as possible and
to treat files as much like other attributes as possible. This means
they aren't saved to their final locations on disk, nor are they
deleted if set to nil, until ActiveRecord::Base#save is called. It
manages validations based on size and presence, if required. It can
transform its assigned image into thumbnails if needed, and the
prerequisites are as simple as installing ImageMagick (which, for most
modern Unix-based systems, is as easy as installing the right
packages). Attached files are saved to the filesystem and referenced
in the browser by an easily understandable specification, which has
sensible and useful defaults.
Paperclip can work exclusive to ImageMagick to manage the uploaded images. ImageMagick is an "optional extra", allowing you to crop / edit images on the fly. Like ffmpeg
(the video equivalent to ImageMagick), you can run Paperclip on its own
If you want to crop images etc - you'll have to install the library files for ImageMagick on your system. This is simple on Linux, much trickier on Windows
--
Heroku
We're very fortunate in that Heroku is designed to give RoR a stable environment to run with. That said, Heroku does this by providing as much functionality as possible - including the ability to install ImageMagick
on the system
Heroku runs linux on Amazon's AWS infrastructure. This means it's relatively simple to use ImageMagick with it - you just need to add it to your gemfile & Heroku will handle the rest
ImageMagick/Paperclip - Paperclip fails during large job
It appears as though this problem was solved by limiting the number of concurrent workers used with sidekiq to just 1. This can be done by specifying -c 1
when booting up sidekiq.
paperclip imagemagick convert to grayscale and crop to fit 144x144#
I decided to go the other way, so I'll just use the cropped file that has the desired size and use imagemagick to convert that one to grayscale and save it into the right folder after the model is saved. The grayscale processor can be removed as I used a system command to work with imagemagick.
p.s. There might be some downsides of this answer, but for now I couldn't find any.
Client.rb
has_attached_file :avatar,
:path => ":rails_root/public/system/:attachment/:id/:style/:filename",
:url => "/system/:attachment/:id/:style/:filename",
:styles => {:thumb => "144x144#", :grayscale => "144x144#"}
after_save :convert_grayscale
def convert_grayscale
system "convert public/system/avatars/#{self.id}/thumb/#{self.avatar.original_filename} -fx '(r+g+b)/3' public/system/avatars/#{self.id}/grayscale/#{self.avatar.original_filename}"
end
result
Related Topics
Rails: Money Gem Converts All Amounts to Zero
How to Check to See If a File Exists (On the Remote Server) in Capistrano
Guidelines for Where to Put Classes in Rails Apps That Don't Fit Anywhere
After Gem Update: Test Fail with "Asset Was Not Declared to Be Precompiled in Production"
Installing Rails: "File Not Found: Lib"
Ruby: Finding Most Recently Modified File
Is 'Yield Self' the Same as Instance_Eval
Rubygems + Cygwin: Posix Path Not Found by Ruby.Exe
How to Take Screenshots of Web Pages Using Ruby and a Unix Server
Modifying Database Ids from Rails Console
How to Run Rake Tasks Within My Rails Application
Calling Method in Parent Class from Subclass Methods in Ruby
Ruby Check If Nil Before Calling Method
What Is the Expected Syntax for Checking Exception Messages in Minitest's Assert_Raises/Must_Raise