0
나는 Rails 4.2와 Mongoid가있는 웹 사이트를 만들고있다. mongoid-paperclip을 사용하고 있는데, 짧은면의 치수를 유지하면서 사각형에 이미지를 자르려고합니다 (이미지가 전체 사각형을 채울 것입니다). 여기 내 사용자 지정 프로세서의 :클립으로 이미지를 수동으로 자르는 방법은 무엇입니까?
module Paperclip
class Cropper < Thumbnail
def initialize(file, options = {}, attachment = nil)
super
@preserved_size = [@current_geometry.width, @current_geometry.height].min
@current_geometry.width = @preserved_size
@current_geometry.height = @preserved_size
end
def target
@attachment.instance
end
def transformation_command
if crop_command
crop_command + super.join(' ').sub(/ -crop \S+/, '').split(' ')
else
super
end
end
def crop_command
["-crop", "#{@preserved_size}x#{@preserved_size}+#{@preserved_size}+#{@preserved_size}"]
end
end
end
그리고 그것은 외모에 붙어 모델이 라인을 가지고 :
has_mongoid_attached_file :image, styles: {square: {processors: [:cropper]}}
을하지만 작동하지 않습니다. 'square'라는 이미지 버전이 저장되지만 원래 이미지와 동일합니다. 어떻게 작동시킬 수 있습니까?