I need the ability to put the processed image's dimensions.
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)
You can adjust and use the method described here: http://code.dblock.org/carrierwave-saving-best-image-geometry
It adds a process then call Magick's method to fetch image geometry.
Code:
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
You can hook onto the :cache and :retrieve_from_cache methods
There is no need to rely on system commands either:
# Somewhere in your uploader:
attr_reader :geometry
after :cache, :capture_size
after :retrieve_from_cache, :capture_size
def capture_size(*args)
img = ::MiniMagick::Image::read(File.binread(@file.file))
@geometry = [img[:width], img[:height]]
end
http://www.glebm.com/2012/05/carrierwave-image-dimensions.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With