|
What we're listening to:
|
validate image dimensions with paperclipJanuary 31st, 2009I’m liking paperclip, in a recent project I chose it specifically because it buffers writes on uploads, which should help keep memory usage down. I needed to validate that an uploaded image was at least a certian size, and it was a little tricky, but here’s what I came up with:
has_attached_file :image,
:styles => { :original => ["1000x600>", :jpg]},
:whiny_thumbnails => true
def validate
dimensions = Paperclip::Geometry.from_file(self.image.queued_for_write[:original])
self.errors.add(:image, "Please upload a file at least 700 pixels wide") if dimensions.width < 700
self.errors.add(:image, "Please upload a file at least 200 pixels tall") if dimensions.height < 200
end
like it? hate it? have something better?
|