我正在构建一个博客文章,在文章模型中,我使用aws-sdk和minimagik上传图像。我有一种方法可以获取缩略图的网址,以显示在这样的每篇文章中
class Post < ApplicationRecord
has_one_attached :post_thumbnails
def thumb_url(width=200,heigh=200)
return unless post_thumbnails.attached?
image_dimension = "#{width}x#{heigh}"
Rails.application.routes.url_helpers.rails_representation_url(post_thumbnails.variant(
combine_options: [
[:resize,"#{image_dimension}^"],[:gravity,"center"],[:crop,"#{image_dimension}+0+0"],[:strip,true],[:quality,"70"],[:repage,nil],[:+,# +repage
[:distort,"Perspective"]
]
).processed,only_path: true)
end
end
我正在努力寻找获取缩略图URL或仅调整图像大小以减少S3上存储空间的更好方法,实际上我不需要使用缩略图的原始版本
任何人都可以帮助我获得更好的解决方案,以便在通过大小后获得不同的缩略图大小,我知道activeStorage::Variant
会获得不同大小的图像activestorage
。