gpt4 book ai didi

ruby-on-rails - 旋转附有回形针的图像

转载 作者:行者123 更新时间:2023-12-03 08:34:44 25 4
gpt4 key购买 nike

我们有一个使用 Paperclip (4.2.0) 附上头像的 AR 模型。我们希望允许用户旋转此图像,但我很难让它发挥作用。我的代码如下所示:

module Paperclip
class Rotator < Thumbnail
def initialize(file, options = {}, attachment = nil)
options[:auto_orient] = false
super
end

def transformation_command
if rotate_command
"#{rotate_command} #{super.join(' ')}"
else
super
end
end

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

class User < ActiveRecord::Base
has_attached_file :avatar, {
styles: {
small: ['72x72#', :png]
},
processors: [:rotator]
}
attr_accessor :rotate
end

我正在尝试通过执行以下操作来旋转图像:

user.rotate = 90
user.avatar.reprocess!

我可以看到传递给 convert 的 -rotate 90 选项,但它什么也没做。有没有人设法使用回形针来完成这项工作?

最佳答案

target.rotation 替换为 target.rotate 并在 rotate_method 中添加尾随空格对我来说是个窍门。

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

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

class User < ActiveRecord::Base
has_attached_file :avatar, {
styles: {
small: ['72x72#', :png]
},
processors: [:rotator]
}
attr_accessor :rotate
end

关于ruby-on-rails - 旋转附有回形针的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25207839/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com