diff --git a/suchwow/_models.py b/suchwow/_models.py
index 7ca2552..8620705 100644
--- a/suchwow/_models.py
+++ b/suchwow/_models.py
@@ -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,
diff --git a/suchwow/cli.py b/suchwow/cli.py
index fd5a8d1..37254e7 100644
--- a/suchwow/cli.py
+++ b/suchwow/cli.py
@@ -2,7 +2,7 @@ from os import makedirs, getenv
from random import choice
from datetime import datetime
-import lorem
+import lorem, click
from flask import Blueprint
from suchwow._models import db, User, Post, AuditEvent, TipSent, TipReceived, Vote
@@ -102,7 +102,15 @@ def payout_users():
wownero.from_atomic(sent), wownero.from_atomic(to_send)
))
-
+@bp.cli.command('fix_image')
+@click.argument('post_id')
+def fix_image(post_id):
+ p = Post.filter(id=post_id).first()
+ if p:
+ p.strip_exif()
+ p.resize_image()
+ else:
+ print("That post doesn't exist")
@bp.cli.command('rescan')
def rescan():
diff --git a/suchwow/templates/index.html b/suchwow/templates/index.html
index 1f2af8c..35849d3 100644
--- a/suchwow/templates/index.html
+++ b/suchwow/templates/index.html
@@ -27,7 +27,7 @@
Your browser does not support the video tag.
{% else %}
-
+
{% endif %}