mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 14:13:21 +00:00
Add overwrite mode and change compressed size width in picture resizing
This commit is contained in:
parent
f09cea4033
commit
4ae4d2b6db
@ -44,14 +44,18 @@ class Picture(SithFile):
|
|||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse('sas:picture', kwargs={'picture_id': self.id})
|
return reverse('sas:picture', kwargs={'picture_id': self.id})
|
||||||
|
|
||||||
def generate_thumbnails(self):
|
def generate_thumbnails(self, overwrite=False):
|
||||||
im = Image.open(BytesIO(self.file.read()))
|
im = Image.open(BytesIO(self.file.read()))
|
||||||
try:
|
try:
|
||||||
im = exif_auto_rotate(im)
|
im = exif_auto_rotate(im)
|
||||||
except: pass
|
except: pass
|
||||||
file = resize_image(im, max(im.size), self.mime_type.split('/')[-1])
|
file = resize_image(im, max(im.size), self.mime_type.split('/')[-1])
|
||||||
thumb = resize_image(im, 200, self.mime_type.split('/')[-1])
|
thumb = resize_image(im, 200, self.mime_type.split('/')[-1])
|
||||||
compressed = resize_image(im, 600, self.mime_type.split('/')[-1])
|
compressed = resize_image(im, 1200, self.mime_type.split('/')[-1])
|
||||||
|
if overwrite:
|
||||||
|
self.file.delete()
|
||||||
|
self.thumbnail.delete()
|
||||||
|
self.compressed.delete()
|
||||||
self.file = file
|
self.file = file
|
||||||
self.file.name = self.name
|
self.file.name = self.name
|
||||||
self.thumbnail = thumb
|
self.thumbnail = thumb
|
||||||
|
Loading…
Reference in New Issue
Block a user