ruby-on-rails-3 - 如何将 ImageMagick 命令行选项转换为 MiniMagick 以在 CarrierWave 中使用

标签 ruby-on-rails-3 imagemagick carrierwave minimagick

我试图将此命令行选项转换为在carrierwave中使用的处理器方法,但我无法让它工作。我在关注 method I saw here .

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

最佳答案

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

但这并不能解释 nil:NilClass。

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

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.



明白了

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

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

关于ruby-on-rails-3 - 如何将 ImageMagick 命令行选项转换为 MiniMagick 以在 CarrierWave 中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9693258/

相关文章:

imagemagick - 使用 ImageMagick 调整图像大小并设置背景颜色

node.js - 在 Node Js 中使用 Graphicsmagick 调整图像大小会生成空文件

ruby - ActiveRecord,通过多态属性查找

ruby-on-rails - rails : elsif && conditional statement in controller action not working

ruby-on-rails - 为什么 Foo.first 返回最后一条记录?

imagemagick - 如何使用 ImageMagick 像素化/模糊图像?

ruby-on-rails - Mount_upload 动态场与carrierwave

ruby-on-rails - Rails + CarrierWave : NoMethodError: undefined method `name' for nil:NilClass

ruby-on-rails - 载波。无法使用 STI 保存文件

ruby-on-rails - 如何使用路由 url 助手取消设置子域?