
aifeifei798/Song
Updated
•
1
import re
def remove_emojis(text):
# Define a broader emoji pattern
emoji_pattern = re.compile(
"["
u"\U0001F600-\U0001F64F" # emoticons
u"\U0001F300-\U0001F5FF" # symbols & pictographs
u"\U0001F680-\U0001F6FF" # transport & map symbols
u"\U0001F1E0-\U0001F1FF" # flags (iOS)
u"\U00002702-\U000027B0"
u"\U000024C2-\U0001F251"
u"\U0001F900-\U0001F9FF" # supplemental symbols and pictographs
u"\U0001FA00-\U0001FA6F" # chess symbols and more emojis
u"\U0001FA70-\U0001FAFF" # more symbols and pictographs
u"\U00002600-\U000026FF" # miscellaneous symbols
u"\U00002B50-\U00002B59" # additional symbols
u"\U0000200D" # zero width joiner
u"\U0000200C" # zero width non-joiner
u"\U0000FE0F" # emoji variation selector
"]+", flags=re.UNICODE
)
return emoji_pattern.sub(r'', text)
from PIL import Image, ImageDraw, ImageFont
def add_watermark(image):
watermark_text = "AI Generated by DarkIdol FeiFei"
# Ensure the input is an Image object
if not isinstance(image, Image.Image):
raise ValueError("Input must be a PIL Image object")
width, height = image.size
# Create a drawing object to draw on the image
draw = ImageDraw.Draw(image)
# Set the font size for the watermark text
font_size = 10 # Set font size to 10
try:
# Try to use a common font file
font = ImageFont.truetype("Iansui-Regular.ttf", font_size)
except IOError:
# Use the default font if the specified font file is not found
font = ImageFont.load_default()
# Calculate the width and height of the watermark text using textbbox
bbox = draw.textbbox((0, 0), watermark_text, font=font)
text_width = bbox[2] - bbox[0]
text_height = bbox[3] - bbox[1]
# Calculate the position for the watermark text (bottom-right corner)
x = width - text_width - 10 # 10 is the right margin
y = height - text_height - 10 # 10 is the bottom margin
# Add the watermark text to the image
draw.text((x, y), watermark_text, font=font, fill=(255, 255, 255, 128))
# Return the modified image object
return image