我使用 gem Shrine 在我的网站上上传图像。我想为我的图像设置几个尺寸(创建一个微型相册)
所以我写在我的上传文件中,就像在神社的自述文件中一样:
require "image_processing/mini_magick"
class ImageUploader < Shrine
include ImageProcessing::MiniMagick
plugin :processing
plugin :delete_raw
plugin :determine_mime_type
plugin :logging, logger: Rails.logger
plugin :remove_attachment
plugin :store_dimensions
plugin :validation_helpers
plugin :versions
Attacher.validate do
validate_max_size 5.megabytes, message: 'is too large (max is 5 MB)'
validate_mime_type_inclusion ['image/jpg', 'image/jpeg', 'image/png', 'image/gif']
end
process(:store) do |io, context|
original = io.download
pipeline = ImageProcessing::MiniMagick.source(original)
size_800 = pipeline.resize_to_limit!(800, 800)
size_500 = pipeline.resize_to_limit!(500, 500)
size_300 = pipeline.resize_to_limit!(300, 300)
original.close!
{ original: io, large: size_800, medium: size_500, small: size_300 }
end
end
但是资产 :original :large :medium 和 :small 具有相同的大小......
我可能在我的上传文件中出错了......你能看到吗?