3

我试图将此命令行选项转换为在carrierwave中使用的处理器方法,但我无法让它工作。我按照我在这里看到的方法

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

这是我的 CarrierWave 上传器

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
4

1 回答 1

1

好吧,看起来你的方法应该是mattecolor

但这并不能解释 nil:NilClass。

我想知道您是否必须在上传器中包含 ImageMagick。

操纵!()

使用 RMagick 处理图像。此方法将加载图像,然后将其每个帧传递给提供的块。届时将

将图像保存到磁盘。

明白了

此方法假定对象响应 current_path。该模块混入的任何类都必须具有 current_path 方法。CarrierWave::Uploader 可以,因此在大多数情况下您无需担心这一点。

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

于 2012-03-14T19:34:39.733 回答