I'm using django-stdimage for creating variations of the image.


class Photo(models.Model):
    photo = StdImageField(upload_to='photos', verbose_name=_("photo"),
                      variations={'large': (600, 600), 'thumbnail': (100, 100)}


StdImageField does it's own operations on the image, subclassing ImageField and 
having attr_class = StdImageFieldFile

StdImageFieldFile does the actual save operation


class StdImageFieldFile(ImageFieldFile):
    """
    Like ImageFieldFile but handles variations.
    """

    def save(self, name, content, save=True):
        super(StdImageFieldFile, self).save(name, content, save)
        render_variations = self.field.render_variations
        if callable(render_variations):
            render_variations = render_variations(
                file_name=self.name,
                variations=self.field.variations,
                storage=self.storage,
            )
        if not isinstance(render_variations, bool):
            msg = (
                '"render_variations" callable expects a boolean return value,'
                ' but got %s'
                ) % type(render_variations)
            raise TypeError(msg)
        if render_variations:
            self.render_variations()


However, I want to do some manipulation of the image before 
StdImageFieldFile does it (rotating).

So I created my custom field, to catch the image before it's passed to 
stdimage


class Rotate(ImageFieldFile):
    def save(self, name, content, save=True):
        save = False

        return super(Rotate, self).save(name, content, save)
class StdImageFieldFileRotateMixin(Rotate, StdImageFieldFile):
    pass
class StdImageFieldRotate(StdImageField):
    attr_class = StdImageFieldFileRotateMixin


I have the image in the content property of the Rotate class and I can 
manipulate the image using PIL, but after it's done, I don't know how to 
assign this image back to the content property. It seems that it's 
generated on the lower level. Is there a method to generate this content 
property 
and then MRO will handle the rest (i.e. pass it to StdImageFieldFile and it 
will do the rest)?



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3d492953-d5c5-4f7d-a318-cdbe3929ee74%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to