【问题标题】:How to get height and width of image variant?如何获取图像变体的高度和宽度?
【发布时间】:2020-07-27 21:38:42
【问题描述】:

我需要将图片 url 返回到特定的变体,并返回这个变体图像的高度和宽度

variant = image.variant(resize: '1000x1000')
json.image_url(rails_representation_url(variant))
json.image_width # TODO: best way to receive width of variant
json.image_height # TODO: best way to receive height of variant

【问题讨论】:

    标签: ruby-on-rails rails-activestorage


    【解决方案1】:

    我下一个方法

    variant = image.variant(resize: '1000x1000').processed
    path = variant.service.path_for(variant.key)
    width, height = MiniMagick::Image.new(path)[:dimensions]
    
    json.image_url(rails_representation_url(variant))
    json.image_width(width)
    json.image_height(height)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-31
      • 1970-01-01
      • 2010-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-23
      • 2011-11-26
      相关资源
      最近更新 更多