问题
I need to know the width and height of the current instance of carrierwave
For example:
image_tag image.photo_url,:width => image.photo.width, :height => image.photo.height
But the problem is that image.photo.width and image.photo.height are not working.
Any ideas ?
回答1:
You have to install ImageMagick, RMagick or MiniMagick. Then you open the file (image) before you can find out its height.
Example: https://github.com/jnicklas/carrierwave#conditional-versions (see the is_landscape? method), copied here:
def is_landscape? picture
image = MiniMagick::Image.open(picture.path)
image[:width] > image[:height]
end
Or this other related question:
Carrierwave and mini_magick finding widths & height
来源:https://stackoverflow.com/questions/12022653/ruby-on-rails-carrierwave-get-the-image-dimension-width-and-height