I've been reading about and trying various thumbnailing apps for Django. These are the requirements:
All generated thumbnails must be saved in a S3 bucket separate from the original images, i.e. separate storage class
When the image instance is deleted, the original image file along with all generated thumbnails must be delete as well
Minimize expensive inefficiencies, ex. Fetching the url of a thumbnail to serialize in DRF shouldn't look in S3 bucket to see if it exists every time, etc.
VersatileImageField fails the first requirement. ImageKit fails the second requirement. The third requirement is where I'm most confused; I'm trying to inform myself on best practices but the information is fragmented and I'm not confident in making a decision based on what I've learned so far.
From what I've read, my impression is that the most efficient behavior would be as follows:
I'd be most interested in learning about the differences in the approaches that easy-thumbnails and sorl-thumbnail take (if they align with the process I very briefly outlined above or if they have something even more efficient), and the advantages/disadvantages in each of their methodologies.
I hope this may help you in the model, there are two fields image and thumbnail, in view make validation image type and size after that generate thumbnail using Pill
from PIL import Image as Img
from io import BytesIO
def create(self,request):
mutable = request.POST._mutable
request.POST._mutable = True
for value in request.FILES.items():
im = Img.open(value[1])
im.thumbnail((425, 236), Img.ANTIALIAS)
buffer = BytesIO()
im.save(fp=buffer, format='JPEG')
requset.POST['thumbnail'] = ContentFile(buffer.getvalue(), thumnail_name)
request.POST._mutable = mutable
to save images in folder and thumbnails anther folder you can use different path with upload_to in ImageField
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With