我正在使用minimagick对carrierwave进行一些裁剪。我有3种尺寸,目前裁剪适用于大尺寸,但较小尺寸似乎忽略了裁剪后的图像并从原始图像调整大小。
class PhotoUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
include CarrierWave::Processing::MiniMagick
version :thumb, from_version: :medium do
process resize_to_fill: [100, 100]
end
version :medium, from_version: :large do
process resize_to_fill: [261, 163]
end
version :large do
process :conversion
end
# ... some methods
private
def conversion
manipulate! do |img|
img.format('JPG')
img.strip
if model.croppable?
img.crop("#{model.w}x#{model.h}+#{model.x}+#{model.y}")
end
img = yield(img) if block_given?
img
end
end
end
如何从裁剪的大版本中告诉媒体resize_to_fill,而不是原始版本?
答案 0 :(得分:1)
正如@PinnyM建议的那样,这是指定版本的顺序
class PhotoUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
include CarrierWave::Processing::MiniMagick
# Specify this first!
version :large do
process :conversion
end
version :medium, from_version: :large do
process resize_to_fill: [261, 163]
end
version :thumb, from_version: :medium do
process resize_to_fill: [100, 100]
end
#... everything else
end