Skip to content

Instantly share code, notes, and snippets.

@simryang
Created September 16, 2022 13:57
Show Gist options
  • Save simryang/16f72d7ab90e8a7ce8dec36beecb5038 to your computer and use it in GitHub Desktop.
Save simryang/16f72d7ab90e8a7ce8dec36beecb5038 to your computer and use it in GitHub Desktop.
Add banner to 640x480 image
from PIL import Image, ImageFont, ImageDraw
import time
import datetime
filename = "kk.jpg"
img = Image.open(filename)
img_size = (640, 480)
img_resize = img.resize(img_size)
font_size = 15
#title_font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", font_size)
title_font = ImageFont.truetype("D2Coding-Ver1.3.2-20180524-all.ttc", font_size)
title_text = f"test 123 Il1|한글테스트"
title_text2 = f"{datetime.datetime.fromtimestamp(time.time()).astimezone().strftime('%Y-%m-%d %H:%M:%S %Z')}"
img_edit = ImageDraw.Draw(img_resize, "RGBA")
line_color_RGBA = (255,0,0,255)
box_color_RGBA = (255,0,0,0)
fill_color_RGBA = (0,0,255,70)
img_edit.line([(2,453), (640 - 2, 453)], fill="red", width=1)
img_edit.rectangle((2, 455, 640-2, 480-2),
outline=box_color_RGBA, fill=fill_color_RGBA, width=0)
img_edit.text((3,img_size[1] - font_size - 5), title_text, (237, 230, 211), font=title_font)
img_edit.text((3+435,img_size[1] - font_size - 5), title_text2, (237, 230, 211), font=title_font)
img_resize.save("kkkk.jpg")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment