Carrierwave和mini_magick发现宽度和宽度高度 [英] Carrierwave and mini_magick finding widths & height

查看:127
本文介绍了Carrierwave和mini_magick发现宽度和宽度高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过一番调查后,我决定在我的新rails3应用程序上使用Carrierwave和mini_magick。

After a bit of investigation I decided to use Carrierwave and mini_magick on my new rail3 app.

我已经设置了它,它完美无缺。但是我有一个问题。我希望能够访问宽度和高度,所以我可以正确地形成html。但是,没有用于获取此信息的默认数据。由于它存储数据的方式,我无法想到任何可以将其添加到数据库的方法。

I've set it up and it works perfectly. However I have a one question. I'd like to be able to access the width and height, so I can form the html correctly. However, there is no default data from which to get this information. Because of the way it stores the data I'm I cannot think of any way that I can add it to the database.

有人可以提出任何提示或想法吗?它甚至可能吗?

Can anyone suggest any tips or ideas? Is it even possible?

推荐答案

class Attachment
  mount_uploader :file, FileUploader

  def image
    @image ||= MiniMagick::Image.open(file.path)
  end
end

并像这样使用它:

Attachment.first.image['width'] # => 400
Attachment.first.image['height'] # => 300

这篇关于Carrierwave和mini_magick发现宽度和宽度高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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