diff --git a/nerochan/cli.py b/nerochan/cli.py index 90e8030..0ea80c5 100644 --- a/nerochan/cli.py +++ b/nerochan/cli.py @@ -18,6 +18,12 @@ def cli(app): model = peewee.Model.__subclasses__() db.create_tables(model) + @app.cli.command('regenerate_thumbnails') + def regenerate_thumbnails(): + for artwork in Artwork.select(): + print(f'regenerating thumbnail for artwork {artwork.id}') + artwork.generate_thumbnail() + @click.argument('handle') @app.cli.command('add_admin') def add_admin(handle): diff --git a/nerochan/models.py b/nerochan/models.py index 98b6b17..bb4b1e8 100644 --- a/nerochan/models.py +++ b/nerochan/models.py @@ -3,7 +3,7 @@ from datetime import datetime from secrets import token_urlsafe from flask_login import login_user -from PIL import Image, ImageSequence, ImageFilter +from PIL import Image, ImageSequence, ImageFilter, ImageFont from cv2 import VideoCapture import peewee as pw @@ -122,12 +122,15 @@ class Artwork(pw.Model): image = Image.open(i) frames = ImageSequence.Iterator(image) def thumbnails(frames): + nsfw = Image.open('nerochan/static/images/nsfw.png') for frame in frames: thumbnail = frame.copy().convert('RGBA') thumbnail.thumbnail(size, Image.ANTIALIAS) if self.nsfw: thumbnail = thumbnail.filter(ImageFilter.GaussianBlur(radius = 6)) + thumbnail.paste(nsfw, (int(thumbnail.width / 2) - int(nsfw.width / 2), int(thumbnail.height / 2) - int(nsfw.height / 2)), nsfw) yield thumbnail + nsfw.close() _frames = thumbnails(frames) _image = next(_frames) _image.info = image.info @@ -139,9 +142,12 @@ class Artwork(pw.Model): _, frame = cap.read() image = Image.fromarray(frame) if self.nsfw: + nsfw = Image.open('nerochan/static/images/nsfw.png') image = image.filter(ImageFilter.GaussianBlur(radius = 6)) + image.paste(nsfw, (int(image.width / 2) - int(nsfw.width / 2), int(image.height / 2) - int(nsfw.height / 2)), nsfw) + nsfw.close() pb = Image.open('nerochan/static/images/play.png') - image.paste(pb, (int(image.width / 2) - int(pb.width / 2), int(image.height / 2) - int(pb.height / 2))) + image.paste(pb, (int(image.width / 2) - int(pb.width / 2), int(image.height / 2) - int(pb.height / 2)), pb) pb.close() image.save(t, format=image.format) image.close() @@ -149,7 +155,10 @@ class Artwork(pw.Model): image = Image.open(i) image.thumbnail(size, Image.ANTIALIAS) if self.nsfw: + nsfw = Image.open('nerochan/static/images/nsfw.png') image = image.filter(ImageFilter.GaussianBlur(radius = 6)) + image.paste(nsfw, (int(image.width / 2) - int(nsfw.width / 2), int(image.height / 2) - int(nsfw.height / 2)), nsfw) + nsfw.close() image.save(t, format=image.format) image.close() self.save() diff --git a/nerochan/static/images/nsfw.png b/nerochan/static/images/nsfw.png new file mode 100644 index 0000000..016a245 Binary files /dev/null and b/nerochan/static/images/nsfw.png differ diff --git a/nerochan/static/images/play.png b/nerochan/static/images/play.png index 9f41dee..a3f8c0e 100644 Binary files a/nerochan/static/images/play.png and b/nerochan/static/images/play.png differ