This repository was archived by the owner on Sep 30, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathscript_Stylish text_v1.py
More file actions
55 lines (44 loc) · 2.21 KB
/
Copy pathscript_Stylish text_v1.py
File metadata and controls
55 lines (44 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from PIL import Image, ImageDraw, ImageFont, ImageFilter, ImageOps
def create_stylish_text(text, font_path, output_path, image_size=(800, 600), font_size=100, color="white", bgcolor="black"):
# Create a new image with a solid background
image = Image.new("RGB", image_size, bgcolor)
draw = ImageDraw.Draw(image)
# Load the font
font = ImageFont.truetype(font_path, font_size)
# Calculate text size and position
text_bbox = draw.textbbox((0, 0), text, font=font)
text_width, text_height = text_bbox[2] - text_bbox[0], text_bbox[3] - text_bbox[1]
text_x = (image_size[0] - text_width) // 2
text_y = (image_size[1] - text_height) // 2
# Apply shadow effect
shadow_offset = 10
shadow_color = "grey"
draw.text((text_x + shadow_offset, text_y + shadow_offset), text, font=font, fill=shadow_color)
# Apply outline effect
outline_color = "black"
outline_range = 2
for x in range(-outline_range, outline_range+1):
for y in range(-outline_range, outline_range+1):
draw.text((text_x + x, text_y + y), text, font=font, fill=outline_color)
# Draw the main text
draw.text((text_x, text_y), text, font=font, fill=color)
# Apply gradient effect to the text (optional)
gradient = Image.new("L", (1, text_height), color=0xFF)
for y in range(text_height):
gradient.putpixel((0, y), int(255 * (y / text_height)))
alpha = gradient.resize((text_width, text_height))
black_text = Image.new("RGBA", (text_width, text_height), (0, 0, 0, 255))
draw_text = ImageDraw.Draw(black_text)
draw_text.text((0, 0), text, font=font, fill=color)
gradient_text = Image.composite(black_text, Image.new("RGBA", black_text.size, (0, 0, 0, 0)), alpha)
image.paste(gradient_text, (text_x, text_y), gradient_text)
# Apply a filter to make the text more stylish
image = image.filter(ImageFilter.SMOOTH_MORE)
# Save the image
image.save(output_path)
# Define the paths and text
text = "Love u Jodha"
font_path = "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf" # Update with your font path
output_path = "/home/jasvir/Music/Jodha/stylish_text.png"
# Create stylish text with effects
create_stylish_text(text, font_path, output_path)