On Nov 30, 2008, at 10:36 PM, Alex Jonsson wrote:
> > Hey guys, > > I have an application where I want my users to be able to upload a > picture. The model contains a name field and a ImageField. > > My question is how the easiest way would be to modify this image > before saving it? That is, cropping it down to a certain size and > renaming it to the person's name instead of having randomly named > files in my folders. The most direct method is overriding the model's save() method. Every time a picture instance is saved, it will go through whatever you put in the save method -- usually this means using the PIL library, which may or may not be installed in your production environment. Use the PIL.Image class to open the image (ie img = Image.open(self.imagefield.path)) and manipulate it, then resave it. Check out both PIL: http://www.pythonware.com/products/pil/ and the django file storage docs: http://docs.djangoproject.com/en/dev/ref/models/fields/#imagefield Note that changing the path to something relative to the currently logged-in user will be a little more difficult. As far as I know the thread-locals hack is still required there... E > > > Thanks, > Alex > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---

