首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Process imagemagick函数不使用Dragonfly::Processor

Process imagemagick函数不使用Dragonfly::Processor
EN

Stack Overflow用户
提问于 2012-07-17 07:59:28
回答 1查看 1.1K关注 0票数 1

在我的用户模型中,我希望在上传时调整图像的大小。我将图片存储在亚马逊的s3上。一切都很好,图像显示、上传、删除等等,直到我尝试将after_assign方法添加到image_accessor块中。

这里是错误:

代码语言:javascript
复制
None of the functions registered with Dragonfly::Processor were able to deal with the 
method call thumb

我已经在网上学习了教程,并且仔细检查了所有的内容。我认为这是一个与映像或rmagick错误,但在重新安装后,我感到不知所措。对于$ which convert,我的路径是/opt/local/bin/转换,我很确定这条路径显示得很好。

对如何使流程工作有任何建议吗?我正在运行雪豹,Ruby1.9.3和Rails 3.2.5

供参考:

这是我的用户模型:

代码语言:javascript
复制
class User < ActiveRecord::Base

    image_accessor :avatar do
      storage_path{ |file| "#{self.id}/avatar/#{rand(1000)}.#{file.format}" }
      after_assign{ |a| a.thumb!('300x300#') }
    end

  ...

  attr_accessible :name, :location, :avatar, :retained_avatar,
    # Used by Devise
    :email, :password, :password_confirmation, :remember_me, :confirmed_at

  validates_size_of      :avatar, maximum: 5.megabytes, allow_nil: true
  validates_property :format, of: :avatar, 
    in: [ :jpg, :png, :gif ], case_sensitive: false, allow_nil: true, 
    message: "Only .jpg, .png and .gif file formats are supported."

end

这是我的蜻蜓初始化器

代码语言:javascript
复制
require 'dragonfly'

app = Dragonfly[:images]

app.configure_with(:imagemagick)
app.configure_with(:rails)

app.datastore = Dragonfly::DataStorage::S3DataStore.new

app.datastore.configure do |c|
  c.bucket_name = ENV['S3_BUCKET']
  c.access_key_id = ENV['S3_KEY']
  c.secret_access_key = ENV['S3_SECRET']
  c.url_scheme = 'https' 
end

app.define_macro(ActiveRecord::Base, :image_accessor)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-07-19 10:20:42

如果您的文件名为:photo,那么它的after_assign应该是after_assign { |a| self.photo = a.thumb('300x300#) }

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11518280

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档