3

I tried to convert this command line option to a processor method to use in carrierwave but I couldn't get it to work. I was following the method I saw here.

convert E22725-89PC.jpg -matte -fill none -fuzz 15% -opaque white result.png

Here is my CarrierWave uploader

class ImageUploader < CarrierWave::Uploader::Base
  include CarrierWave::MiniMagick

  storage :file

  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  process :remove_background => 'white'

  def remove_background(color)
    manipulate! do |img|
      img = img.format 'png'
      img = img.matte
      img = img.fill 'none'
      img = img.fuzz '15%'
      img = img.opaque color
    end
  end

end
hadees
  • 1,754
  • 2
  • 25
  • 36

1 Answers1

1

Well, it looks like your method should be mattecolor

But that doesn't account for the nil:NilClass.

I wonder if you have to include ImageMagick in your uploader.

manipulate!()

Manipulate the image with RMagick. This method will load up an image and then pass each of its frames to the supplied block. It will then

save the image to disk.

Gotcha

This method assumes that the object responds to current_path. Any class that this module is mixed into must have a current_path method. CarrierWave::Uploader does, so you won’t need to worry about this in most cases.

http://carrierwave.rubyforge.org/rdoc/classes/CarrierWave/MiniMagick.html#M000063

Ed Jones
  • 653
  • 1
  • 4
  • 19
  • matte is a different option but the way they have MiniMagick in the example doesn't work for me using those options. – hadees Mar 15 '12 at 00:34
  • I guess I didn't write that clearly. Matte was not among the methods available on the command-line options referenced by the mini-magick extension. http://www.imagemagick.org/script/command-line-options.php?ImageMagick=es52ar3uvqnue5rok5kbda5gb6 – Ed Jones Mar 15 '12 at 01:54
  • 1
    Did you try including ImageMagick in your uploader? – Ed Jones Mar 15 '12 at 01:54