2
그림과 같은 간단한 텍스트로 글을 쓰고 싶을뿐입니다. PIL로 어떻게 할 수 있습니까?PIL로 그림의 오버레이 텍스트
그림과 같은 간단한 텍스트로 글을 쓰고 싶을뿐입니다. PIL로 어떻게 할 수 있습니까?PIL로 그림의 오버레이 텍스트
먼저 (pip install Pillow
)
참고 파이썬 이미징 라이브러리를 설치 : 당신이 당신의 글꼴 파일 font_fname
의 경로를 변경해야 할 수도 있습니다.
import scipy as sp
import PIL
import PIL.Image as Image
import PIL.ImageDraw as ImageDraw
import PIL.ImageFont as ImageFont
font_fname = '/usr/share/fonts/truetype/freefont/FreeSansBold.ttf'
font_size = 200
font = ImageFont.truetype(font_fname, font_size)
h, w = 1080, 1920
bg_colour = (255, 255, 255)
bg_image = sp.dot(sp.ones((h,w,3), dtype='uint8'), sp.diag(sp.asarray((bg_colour), dtype='uint8')))
image0 = Image.fromarray(bg_image)
draw = ImageDraw.Draw(image0)
draw.text((530, 160), "hello world", font=font, fill='rgb(0, 0, 0)')
image0.save('hello_world.jpg')
특수 효과 (예 : 그림자, 확장, 노이즈 등)를 추가하는 방법은 무엇입니까? – NightFury13