I'm completely lost on how I should modify an image after it's saved. I have a model:
class Pic(models.Model):
imgfile = FaceChopField(upload_to='img/%m/%d')
The image is uploaded just fine. I've looked up this question a bunch, and I've found a number of snippets and similar questions, but I'm still terribly confused. Yes, I have gone through a bunch of searches regarding this exact sort of confusion/issue.
Is there any way I can just:
- Access the saved image directory.
- Locate the image uploaded by name/directory.
- Run my modify_image(filename) on the image.
- Save the modified image in some other directory.
I've read through documentation on the Django site on managing files, and I've pored over StackOverflow for a while, trying different solutions. All I'm asking for is, perhaps, a straightforward approach to the aforementioned. You don't even need to show me any code if it's too much of a bother. I'm just at a loss and I don't know what I'm doing at this point, so some algorithmic layout of a solution would be great. Thank you.
Here's my current attempt:
class FaceChopFieldFile(ImageFieldFile):
def __init__(self, *args, **kwargs):
super(FaceChopFieldFile, self).__init__(*args, **kwargs)
def save(self):
super(FaceChopFieldFile, self).save()
image_content = facechop(self.path) #my image modification function
self.storage.save(self.path, image_content)
class FaceChopField(ImageField):
attr_class = FaceChopFieldFile
class Pic(models.Model):
imgfile = FaceChopField(upload_to='img/%m/%d')
Anything wrong?