Search code examples
ruby-on-railsimagemagickimagemagick-convert

Using convert options for ImageMagick in rails


Working on a project that will allow conversion of an uploaded pdf to png. Here's what I've got so far:

 class MyModel < ActiveRecord::Base

          has_attached_file :attachment1, 
             styles: { image: ["1125x1500", :png] }, 
             default_url: "/images/missing.png", 
             :convert_options => { density: "1050", quality: "1050" }

{other stuff}
end

The convert_options doesn't seem to be working, as adjusting the density and quality seem to make no changes in the image. I fear I'm not using correct syntax here.


Solution

  • The convert_options uses the key as the image style, and the value is the string of options:

    class MyModel < ActiveRecord::Base
      has_attached_file :attachment1, 
         styles: { image: ["1125x1500", :png] }, 
         default_url: "/images/missing.png", 
         :convert_options => { image: "-density 1050 -quality 1050" }
    
      {other stuff}
    end