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

发布于 2025-01-07 16:38:26 字数 511 浏览 3 评论 0原文

我正在从 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),但我不确定如何转换所有其他命令。

PS 如果我可以重用现有的 ImageMagick 命令和参数,甚至用于调整大小(即不使用内置帮助程序调整器),那就更好了。

I am migrating from Paperclip to Carrierwave. Here I am trying to convert the processing commands for thumbnail generations:

  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'
    }

I am planning to use MiniMagick. I got that I convert from 220x140# to resize_to_fill(220,140), but I am not sure how to convert all the other commands.

P.S. It would be better if I can reuse the existing ImageMagick commands and parameters, even for resizing (i.e. not using built-in helper resizer).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尤怨 2025-01-14 16:38:27

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

  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

I have done the following. However I am not sure if it is totally equivalent.

  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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文