【问题标题】:Rotate image with Paperclip 5用回形针 5 旋转图像
【发布时间】:2017-03-07 15:03:01
【问题描述】:

我的模型上有照片

has_attached_file :photo, BucketConfig.default.merge(
      processors: [:rotator],
      styles: {
          original: Proc.new { |a| { rotation: a.rotation } }
      },
      default_url:  ActionController::Base.helpers.asset_path('assets/request_default.png')
  )

为了捕捉旋转参数,我做了这样的事情

attr_accessor :rotation

    before_save :adjust_rotation
    before_update :reprocess_image

    protected

    def adjust_rotation
      self.rotation = self.rotation.to_i
      self.rotation = self.rotation % 360 if self.rotation >= 360 || self.rotation <= -360
    end

    def reprocess_image
      self.photo.reprocess! unless self.rotation.zero?
    end

我在 lib/paperclip 中的 Rotator 进程

module Paperclip
  class Rotator < Processor
    def transformation_command
      if rotator_command
        rotator_command + super.join(' ')
      else
        super
      end
    end

    def rotator_command
      target = @attachment
      if target.rotation.present?
        " -rotate #{target.rotation} "
      end
    end
  end
end

当我打电话时

m = Model.first
m.rotation=90
m.save

我有错误:

NoMethodError - undefined method `closed?' for nil:NilClass
Did you mean?  clone:
  paperclip (4.3.7) lib/paperclip/attachment.rb:582:in `block in unlink_files'
  paperclip (4.3.7) lib/paperclip/attachment.rb:581:in `unlink_files'
  paperclip (4.3.7) lib/paperclip/attachment.rb:536:in `post_process_style'
  paperclip (4.3.7) lib/paperclip/attachment.rb:511:in `post_process_styles'
  paperclip (4.3.7) lib/paperclip/attachment.rb:504:in `block (2 levels) in post_process'

为什么我要重新处理!方法行不通?我的旋转过程有问题吗?问题出在哪里?

【问题讨论】:

  • 关于这个问题的任何更新?

标签: ruby-on-rails ruby rotation paperclip


【解决方案1】:

你没有make方法:https://github.com/rezeko/paperclip/blob/master/lib/paperclip/processor.rb#L9

解决方法是使用class Rotator &lt; Thumbnail,并仅继承默认处理器的处理设置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-18
    • 1970-01-01
    • 1970-01-01
    • 2012-03-15
    • 2019-02-22
    • 1970-01-01
    • 1970-01-01
    • 2012-08-19
    相关资源
    最近更新 更多