【问题标题】:How to make custom paperclip processors to resize image size如何制作自定义回形针处理器来调整图像大小
【发布时间】:2012-04-10 13:48:43
【问题描述】:

我正在使用回形针来调整我的 rails 应用程序中的图像大小,就像这样

has_attached_file :photo, :styles => { :medium => "300x300>" }

这给了我一个 60kb 大小的图像,我想使用回形针处理器制作一些自定义方法来减小图像大小,我该怎么做以及如何直接从这些过程中调用 imagemagick 函数?

谢谢

【问题讨论】:

  • + 1 表示如何直接从这些进程中调用 imagemagick 函数?
  • @saurabh - 使用 :convert_options,例如 has_attached_file :photo, :convert_options => {:name_of_style => "imagemagick stuff"}

标签: ruby-on-rails imagemagick paperclip


【解决方案1】:

在我的图片模型中:

  has_attached_file :picture,
                    :storage => :s3,
                    :s3_credentials => "#{RAILS_ROOT}/config/amazon_s3.yml",
                    :styles => { :original => "319x228#", :thumb => "100x60#" },
                    :path => "article/:attachment/:id/:style/:basename.:extension",
                    :bucket => YAML.load_file("#{RAILS_ROOT}/config/amazon_s3.yml")[RAILS_ENV]["bucket_name"]
  validates_attachment_content_type :picture, :content_type => ['image/jpeg', 'image/pjpeg', 'image/jpg', 'image/gif', 'image/png']

【讨论】:

    猜你喜欢
    • 2016-12-10
    • 2011-01-24
    • 1970-01-01
    • 1970-01-01
    • 2014-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多