使用CarrierWave检索图像高度 [英] Retrieving image height with CarrierWave

查看:54
本文介绍了使用CarrierWave检索图像高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够放置处理后图像的尺寸。

I need the ability to put the processed image's dimensions.

我在 ImageUploader 类中: / p>

I have in my ImageUploader class:

version :post do
  process :resize_to_fit => [200, nil]
end

有没有一种方法可以获取图像的尺寸

Is there a way that I could get the image's dimensions similar to this?

height = @picture.image_height(:post)


推荐答案

您可以调整并使用此处描述的方法: http://code.dblock.org/carrierwave-saving-best-image-geometry

You can adjust and use the method described here: http://code.dblock.org/carrierwave-saving-best-image-geometry

它添加了一个过程,然后调用了Magick的方法来获取图像几何。

It adds a process then call Magick's method to fetch image geometry.

代码:

  version :post do
    process :resize_to_fit => [200, nil]
    process :get_geometry

    def geometry
      @geometry
    end
  end

  def get_geometry
    if (@file)
      img = ::Magick::Image::read(@file.file).first
      @geometry = [ img.columns, img.rows ]
    end
  end

这篇关于使用CarrierWave检索图像高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆