开发者

creating a croppable image field - how to store the widget's data?

I am wondering how to best implement a croppable ImageField in Django.

Basically i'd like to upload images and crop them. For example 开发者_如何学编程using imagAreaSelect

The first approach that came to my mind was to create an ImageField and some meta fields on my model to store the crop ratio, width and height of my selection. But i wonder if the there are cleaner ways to solve this and to further encapsulate the cropping behaviour.

So ultimately i'd like to wrap the desired behaviour in a widget. Though the problem i see is that widgets are usually mapped to single database field.

So i wonder if this is doable at all and how to best persist my image data?


We ended up creating a reusable app for cropping images: django-image-cropping


There's a couple ways of doing this. One way is to infer the name of the cropped image from the name of the uncropped image. So if you have an ImageField, and there is an image named uploads/images/family.jpg, your CropableImageWidget might assume that the cropped image is stored at uploads/images/cropped/family.jpg.

The other way is to make your own database field type that stores a serialized representation of all the files you create while cropping. Could be Via JSON.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜