开发者

Restrict paperclip for fixed dimensions

How can restrict/ validat开发者_运维技巧e paperclip for uploading image with fixed dimentions.

I want to upload image with a fixed dimensions else it should show an error displaying that the size is not proper and upload it with fixed size


To get the size of the image, you can do in your model:

def image_valid?
   g = Paperclip::Geometry.from_file(photo.to_file(:original))

   g.width < 500 && g.height < 700 #change these numbers

(Assuming you have a has_attached_file :photo in your model).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜