Below is my validations for image content type which works fine.
validates_attachment_size :icon, :less_than => MAX_SIZE.megabytes, :message => "Max size is 1 mb" validates_attachment_content_type :icon, :content_type => ['image/jpg','image/jpeg', 'image/png', 'image/gif']
BUT
I need to validate the dimensions also and my code is
validates_each :icon do |record, attr, value| if record.icon_file_name dimensions = Paperclip::Geometry.from_file(value.queued_for_write[:original]) if(dimensions.width > 600 || dimensions.height > 400) record.errors.add(:file, " #{record.icon_file_name} dimensions must be less than or equal to 600*400") end end end
AND
it gives imagemagick error Not recognized by the 'identify' command error
Can you put some light on this?
Thanks.
How about using "validate" method instead of "validates_each" http://paulsturgess.co.uk/articles/33-how-to-write-custom-validation-in-ruby-on-rails