worldcompany/djangoembed — Issue #27: Remove ImageField limitation on photo resource providers
Author: shagi
Created: 2012-02-05 17:57:06+00:00
State: open

Currently the resize method of DjangoProvider raises an exception if the
image field is not a ImageFieldFile. However this requirement is used only
to get images heigth and width, and in the same function is already the
code to get those fields with PIL.

With this patch any FileField-like field could be used;
sorl.thumbnail.fields.ImageField for example. (I pasted the patch directly
since didn't find a way to attach files).

```
diff --git a/oembed/providers.py b/oembed/providers.py
index 58f4399..faf8d4c 100644
--- a/oembed/providers.py
+++ b/oembed/providers.py
@@ -459,13 +459,11 @@ class DjangoProvider(BaseProvider):
the url to the new image and the new width & height
(http://path-to-new-image, 300, 300)
"""
- if not isinstance(image_field, ImageFieldFile):
- raise ValueError('image_field must be an instance of django.db.models.fields.files.ImageFieldFile')
-
- if image_field.field.width_field and image_field.field.height_field:
- # use model fields
- current_width = getattr(image_field.instance, image_field.field.width_field)
- current_height = getattr(image_field.instance, image_field.field.height_field)
+ if isinstance(image_field, ImageFieldFile):
+ if image_field.field.width_field and image_field.field.height_field:
+ # use model fields
+ current_width = getattr(image_field.instance, image_field.field.width_field)
+ current_height = getattr(image_field.instance, image_field.field.height_field)
else:
# use PIL
try:
```