Issue
I am returning back to django after a while, and I am a bit confused on how I should go about processing images once they have been uploaded in createview class.
So, I have this:
class SomeModel(models.Model):
full_name = models.CharField(max_length=200)
email_simple = models.EmailField(max_length = 256)
image = models.ImageField(upload_to='images')
def __str__(self):
return self.full_name
class SomeModelForm(forms.ModelForm):
"""Form for the image model"""
class Meta:
model = SomeModel
fields = ('full_name', 'email_simple', 'image')
<form role="form" action="{% url 'upload' %}" enctype="multipart/form-data" method="post">{% csrf_token %}
{{ form.as_p }}
<button type="submit">Upload</button>
</form>
It works fine as in uploads the image, but, before redirecing to say an upload done page, I would like to postprocess this image using custom logic (such as resizing using ffmpeg and processing it further). Which method within CreateView can allow me to do this? or is there a more efficient way to approach this problem?
Thank you.
Solution
if form.is_valid():
instance = form.save()
imag = Image.open(instance.image.path)
output_size = (400, 300) # new size
imag.thumbnail(output_size)
imag.save(instance.image.path)
Answered By - NANDHA KUMAR
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.