|
|
|
@ -85,7 +85,7 @@ class Post(Model):
|
|
|
|
|
def get_image_path(self, thumbnail=False):
|
|
|
|
|
save_path_base = path.join(config.DATA_FOLDER, "uploads")
|
|
|
|
|
if thumbnail:
|
|
|
|
|
save_path = path.join(save_path_base, self.get_thumbnail_name())
|
|
|
|
|
save_path = path.join(save_path_base, self.thumbnail)
|
|
|
|
|
else:
|
|
|
|
|
save_path = path.join(save_path_base, self.image_name)
|
|
|
|
|
return save_path
|
|
|
|
@ -99,8 +99,34 @@ class Post(Model):
|
|
|
|
|
return True
|
|
|
|
|
except:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def strip_exif(self):
|
|
|
|
|
try:
|
|
|
|
|
image = Image.open(self.get_image_path())
|
|
|
|
|
data = image.getdata()
|
|
|
|
|
image_without_exif = Image.new(image.mode, image.size)
|
|
|
|
|
image_without_exif.putdata(data)
|
|
|
|
|
image_without_exif.save(self.get_image_path())
|
|
|
|
|
image_without_exif.close()
|
|
|
|
|
image.close()
|
|
|
|
|
except:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def resize_image(self):
|
|
|
|
|
try:
|
|
|
|
|
with Image.open(self.get_image_path()) as img:
|
|
|
|
|
img.thumbnail((1800,1800))
|
|
|
|
|
img.save(self.get_image_path())
|
|
|
|
|
except:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def resized(self):
|
|
|
|
|
s = path.splitext(self.image_name)
|
|
|
|
|
return s[0] + '.resized' + s[1]
|
|
|
|
|
|
|
|
|
|
def get_thumbnail_name(self):
|
|
|
|
|
@property
|
|
|
|
|
def thumbnail(self):
|
|
|
|
|
s = path.splitext(self.image_name)
|
|
|
|
|
return s[0] + '.thumbnail' + s[1]
|
|
|
|
|
|
|
|
|
@ -121,7 +147,7 @@ class Post(Model):
|
|
|
|
|
'user': self.user.username,
|
|
|
|
|
'image_name': self.image_name,
|
|
|
|
|
'image_path': self.get_image_path(),
|
|
|
|
|
'thumbnail_name': self.get_thumbnail_name(),
|
|
|
|
|
'thumbnail_name': self.thumbnail,
|
|
|
|
|
'thumbnail_path': self.get_image_path(True),
|
|
|
|
|
'account_index': self.account_index,
|
|
|
|
|
'address_index': self.address_index,
|
|
|
|
|