setup nsfw overlay

master
lza_menace 2 years ago
parent 119cc3a2fc
commit e829fd8d54

@ -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):

@ -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()

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 62 KiB

Loading…
Cancel
Save