开发者

Restricting dimensions of ImageFileField data

开发者 https://www.devze.com 2022-12-24 18:48 出处:网络
I\'m trying to make it so that the ImageFileField only accepts image files of a set dimension. I found another post on here which suggest hijacking the \'clean\' met开发者_StackOverflowhod in a form,

I'm trying to make it so that the ImageFileField only accepts image files of a set dimension. I found another post on here which suggest hijacking the 'clean' met开发者_StackOverflowhod in a form, but I was wondering if it would be simpler to create a custom field type instead?

Has anyone got any code snippets which I might be able to use in order to do this? I don't want the image files to be resized at all, just uploaded as they are if they are the correct size.

Much appreciated!


This is a (recent) resizing version of the ImageField form field which sets a max size. You might be able to take inspiration from it for accepting only certain image dimensions (ie, instead of triggering resizing, make the field complain).

http://www.djangosnippets.org/snippets/1966/

Hope that helps

Steve

0

精彩评论

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