Image Validators
A set of validators for image files.
Installation
Add this line to your application's Gemfile:
gem 'image_validators'
And then execute:
$ bundle
Or install it yourself as:
$ gem install image_validators
Usage
In your model you have a image file attribute attached by using Paperclip:
class User < ActiveRecord::Base
has_attached_file :photo, :styles => {:medium => "620x620>", :thumb => "200x200#"}
Validation of image dimensions
To validate the width and height of the image are greater or equal than 620x620, add to your model:
validates :image, :dimensions => {:greater_than_or_equal_to => {width: 620, height: 620}}
You can validate your image dimensions whith these operations: :less_than
, :less_than_or_equal_to
, :greater_than
, :greater_than_or_equal_to
, or :equal_to
.
Optionally you can also specify an error message:
validates :image, :dimensions => {:equal_to => {width: 620}, :message => "Invalid image dimensions"}
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request