Skip to content

Commit 553a902

Browse files
Merge pull request Mrinank-Bhowmick#670 from vagxrth/main
Instagram Post Creation Project
2 parents eaa9d06 + c2d92ea commit 553a902

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,7 @@ dmypy.json
153153
cython_debug/
154154

155155
*.db
156-
.idea/
156+
.idea/
157+
158+
#.DS_Store
159+
.DS_Store.DS_Store
155 KB
Binary file not shown.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import os
2+
3+
from PIL import Image, ImageDraw, ImageFont
4+
5+
def create_instagram_post(template, text, output_path):
6+
# Load the template image
7+
template_path = os.path.join(os.path.dirname(__file__), "templates", "basic_template.jpg")
8+
img = Image.open(template_path)
9+
10+
# Initialize the drawing context
11+
draw = ImageDraw.Draw(img)
12+
font_path = os.path.join(os.path.dirname(__file__), "fonts", "Poppins-Regular.ttf")
13+
font_size = 30
14+
font = ImageFont.truetype(font_path, font_size)
15+
16+
# Calculate text position
17+
text_bbox = draw.textbbox((0, 0), text, font=font)
18+
text_width = text_bbox[2] - text_bbox[0]
19+
text_height = text_bbox[3] - text_bbox[1]
20+
x = (img.width - text_width) // 2
21+
y = img.height - text_height - 20
22+
23+
# Add text to the image
24+
draw.text((x, y), text, font=font, fill="white")
25+
26+
os.makedirs(os.path.dirname(output_path), exist_ok=True)
27+
28+
# Save the final image
29+
img.save(output_path)
30+
print(f"Instagram post saved to {output_path}")
31+
32+
33+
template_name = "basic_template"
34+
post_text = "My Instagram Post"
35+
output_file = "output/post.jpg"
36+
37+
create_instagram_post(template_name, post_text, output_file)
102 KB
Loading
492 KB
Loading

0 commit comments

Comments
 (0)