Validate image size in carrierwave uploader

Kir picture Kir · Sep 23, 2011 · Viewed 8.8k times · Source

All uploads should be at least 150x150 pixels. How to validate it with Carrierwave?

Answer

skalee picture skalee · Jun 3, 2012

Why not to use MiniMagick? Modified DelPiero's answer:

validate :validate_minimum_image_size

def validate_minimum_image_size
  image = MiniMagick::Image.open(picture.path)
  unless image[:width] > 400 && image[:height] > 400
    errors.add :image, "should be 400x400px minimum!" 
  end
end