如何将缩略图生成规则从回形针转换为载波

时间:2012-02-22 04:11:20

标签: paperclip carrierwave

我正在从Paperclip迁移到Carrierwave。在这里,我试图转换缩略图生成的处理命令:

  has_attached_file :image,
    styles: {
      thumb: '220x140#',
      big: '620x600>',
      no_proportion: '255x162!'
    },
    convert_options: {
      all: '-strip',
      thumb: '-delete 1--1',
      no_proportion: '-delete 1--1'
    }

我打算使用MiniMagick。我知道我从220x140#转换为resize_to_fill(220,140),但我不确定如何转换所有其他命令。

P.S。如果我可以重用现有的ImageMagick命令和参数,即使是调整大小(即不使用内置辅助大小调整器),也会更好。

1 个答案:

答案 0 :(得分:0)

我做了以下事情。但是我不确定它是否完全等同。

  process :strip

  # Create different versions of your uploaded files:
  version :thumb do
    process :resize_to_fill => [220,140]
  end
  version :mobile do
    process :resize_to_fill => [320,210]
  end
  version :mobile_small do
    process :resize_to_fill => [256,168]
  end
  version :big do
    process :resize_to_limit => [620,600]
  end
  version :groupbuy_ad do
    process :resize_to_fill => [96,60]
  end
  version :email do
    process :resize_to_fill => [125,125]
  end
  version :widget_165 do
    process :resize_to_fill => [165,105]
  end
  version :widget_100 do
    process :resize_to_fill => [100,64]
  end
  version :no_proportion do
    process :resize => '255x162!'
  end

  def strip
    manipulate! do |img|
      img.strip
      img = yield(img) if block_given?
      img
    end
  end

  def resize(dimension)
    manipulate! do |img|
      img.resize dimension
      img = yield(img) if block_given?
      img
    end
  end

  def get_first_frame
    manipulate! do |img|
      img = img.delete '1--1'
    end
  end
相关问题