araten10 / EdgewarePlusPlus

Expansion to PetitTournesol's fetishware "Edgeware", adding more features and config options.
MIT License
57 stars 19 forks source link

[Twitter like captions] Do you accept code submissions? #91

Open Narcissus13 opened 2 months ago

Narcissus13 commented 2 months ago

Hey I had an idea to implement twitter like formatting for captions which I've made work locally as an addition to the caption function. And features:

Essentially you can rip a whole lot of tweets from twitter -> clean them -> and then plug into your captions JSON.

I'm sharing because I thought it was a decent idea -> and I couldn't see a way to make a branch of the repo. If it's worth taking forwards I think some of this code belongs in other modules and should accept parameterization for the 'tweeter'.

example

` def try_caption(self) -> None: if self.settings.captions_in_popups and self.pack.has_captions(self.settings, self.media) and self.width > 400:

                ## Handle emojis in body
        self.im = Image.new("RGB", (800, 1280), (255, 255, 255))
        draw = ImageDraw.Draw(self.im)
        font = ImageFont.truetype('seguiemj.ttf', 16, encoding = 'unic')
        textToDraw = self.pack.random_caption(self.settings,self.media)
        margin = offset = 3
        lines = 1
        for line in textwrap.wrap(textToDraw, width=(self.width/9)):
            draw.multiline_text((margin, offset), line, (51,51,51), font=font, embedded_color=True)
            offset += font.getsize(line)[1]
            lines = lines +1
        if lines < 3:
            lines = 3
        #Function to create twitterlike pfp
        def createProfilePic(splashImage, x, y):
            splashImage = Image.open(splashImage)
            height,width = splashImage.size
            lum_img = Image.new('L', [height,width] , 0) 
            draw = ImageDraw.Draw(lum_img) 
            draw.pieslice([(0,0), (height,width)], 0, 360,fill = 255, outline = "white") 
            img_arr =np.array(splashImage) 
            lum_img_arr =np.array(lum_img) 
            splashImage = np.dstack((img_arr,lum_img_arr))
            self.ph = ImageTk.PhotoImage(Image.fromarray(splashImage).resize((x, y)))
            return self.ph

        #Handle Text
        avatar = "twerpy" + "\u270A "
        dateTw = date.today().strftime("%b %d")
        avatarAT = " @twerpy " + "\u00B7 " + dateTw  + "\n"
        text1 = tk.Text(self, height=lines, width=self.width, font = ("Segoe UI", 12), fg=self.theme.fg, bg=self.theme.bg)

        text1.image_create(tk.END,image = createProfilePic("E:\\Edgeware\\EdgewarePlusPlus\\edgeware\\resource\\captionSplash.jpeg",60,60))
        text1.place(x=0, y=0)

        text2 = tk.Text(self, height=lines, width=self.width, font = ("Segoe UI", 12), relief = "flat", fg=self.theme.fg, bg=self.theme.bg, wrap="word")
        text2.tag_configure('avatar',foreground='#14171A',font=('Segoe UI', 12, 'bold'))      
        text2.tag_configure('avatarAT',foreground='#657786',font=('Segoe UI', 11)) 
        text2.tag_configure('tw',foreground='#14171A',font=('Segoe UI', 10))              
        text2.insert(tk.END, avatar, 'avatar')
        text2.insert(tk.END, avatarAT, 'avatarAT')

        self.im =ImageTk.PhotoImage(self.im)
        text2.image_create(tk.END, image = self.im)
        text2.place(x=70, y=0)`

extensions used

import random import time from threading import Thread from tkinter import Button, Label, TclError, Tk, Toplevel, font as tkFont import tkinter as tk from PIL import ImageTk, Image, ImageDraw, ImageFont from features.misc import open_web from features.theme import get_theme from pack import Pack from panic import panic from roll import roll from screeninfo import get_monitors from settings import Settings from state import State from utils import utils from datetime import date import numpy as np import textwrap

LewdDevelopment commented 2 months ago

Of course, contributions are always appreciated! I think this is a neat idea, we'll think about what would be the best way to include this feature.