Creative Prompters

오늘의 뉴스를 이미지 파일로 바로 받아보는 💌 카드 뉴스 GPT 본문

Creative prompters/제작한 서비스들

오늘의 뉴스를 이미지 파일로 바로 받아보는 💌 카드 뉴스 GPT

Ditto_GPT 2024. 3. 11. 21:25

from PIL import Image, ImageDraw, ImageFont

# Load the selected template
template_path = ""
img = Image.open(template_path)

# Load the custom font
font_path = ""
title_font = ImageFont.truetype(font_path, 30)
description_font = ImageFont.truetype(font_path, 20)

# Define text properties
text_color = "black"
title_spacing = 1.5
description_spacing = 1.2

# Define the positions for titles and descriptions
positions = [(140, 400), (140, 550), (140, 700), (140, 850)]

# Define titles, descriptions, and sources
news_items = []

# Function to add text to the image
def draw_text(draw, text, position, font, spacing, color):
    lines = text.split('\n')
    y_pos = position[1]
    for line in lines:
        width, height = draw.textsize(line, font=font)
        draw.text(((img.width - width) / 2, y_pos), line, font=font, fill=color)
        y_pos += font.getsize(line)[1] * spacing

# Draw the titles and descriptions on the image
draw = ImageDraw.Draw(img)
for i, item in enumerate(news_items):
    title = item["title"]
    description = item["description"]
    source = item["source"]
    full_text = f"{title}\n{source}\n{description}"

    # Draw the full text for each news item
    draw_text(draw, full_text, positions[i], title_font if i % 2 == 0 else description_font, title_spacing if i % 2 == 0 else description_spacing, text_color)

# Save the final image
final_image_path = ""
img.save(final_image_path)
final_image_path

카드뉴스 템플릿에 뉴스가 바로 출력되게 하는 코드를 추가한 카드뉴스 GPT입니다.

ChatGPT - 💌 카드 뉴스 GPT


핵심부터 말씀드리자면,

  1. 정해진 템플릿과 ADA로 실행할 코드 Knowledge로 제공하기
  2. 뉴스 타이틀 시작 좌표 정해주고 고정시키기 입니다.
  3. 그리고 템플릿은 직접 이미지 파일을 넣어줬습니다. 한국어 폰트도 넣어주었구요!

먼저 API는 네이버 뉴스를 사용하였습니다.

키워드를 입력하면, 해당 뉴스를 한 문장으로 요약해줍니다.

템플릿 선택

코드 불러오기

아래의 기본적인 코드에서 템플릿에서 글자 시작 위치를 다르게 하려면 positions path의 좌표를 조정하고 font, text_color 글자 크기 등 원하시는대로 수정해서 텍스트 파일로 넣으시면 됩니다.

단, DO NOT Adjust x, y_positions 을 넣어야 임의로 수정하지 않습니다.

 

 

이렇게 링크로 다운받으실 수 있습니다.

 

x,y 위치 조정하는게 사실 제일 힘들었습니다.. 흑

도움이 되셨다면.. 새로 개설한 디토의 프롬프트 연구소 에도 놀러오세요!:)

그리고 비슷하게 응용해서 제작한 GPT로 부터의 추천서 작성봇도 확인해보세요!