나는 한 번에 한 문자 씩 이미지 캡션을 작성하여 텍스트 애니메이션 프레임을 만드는 Wand on Python에 자동화 된 스크립트를 작성하려고합니다.완드에있는 텍스트 애니메이션을위한 프레임 빌드
문제는 caption 명령을 사용하여 한 글자를 쓸 때 (설명서는 http://docs.wand-py.org/en/0.4.4/wand/image.html) 거대한 글자를 쓰는 반면 전체 텍스트를 쓰면 이미지에 멋지게 들어간다는 것입니다.
나는 가능한 해결책을 생각했다 : 첫 번째 글자 색을 채우고 나머지는 투명하게 만들어야한다. 그러나 캡션 명령은 내가 아는 한 여러 가지 색의 텍스트를 처리 할 수 없다.
누군가 다른 옵션을 제안 할 수 있다면 감사 할 것입니다.
imgname = random.choice(os.listdir('/home/gionny/Downloads/HighResImg'))
text = 'Hello, world! This is a slightly longer sentence.'
fontname = random.choice(os.listdir('/home/gionny/Downloads/font'))
with Image(filename='HighResImg/'+imgname) as i:
font = Font(path = 'font/'+fontname, color = Color('#fff'))
textWidth = i.width*2/3
textHeight = i.height*2/3
offsetLeft = (i.width - textWidth)/2
offsetTop = (i.height - textHeight)/2
with Image(filename='logo.gif') as l:
l.resize(80,80)
l.transparentize(0.7)
with Drawing() as draw:
draw.composite(operator='atop', left=i.width-90, top=i.height-90, width=l.width, height=l.height, image=l)
for c in range(0, len(text)):
caption = i.caption(text = text[c], left = offsetLeft, top = offsetTop, width=textWidth, height=textHeight, font = font, gravity = 'center')
print(caption)
cl = i.clone()
cl.format = 'jpeg'
cl.save(filename='Text/text'+str(c)+'.jpg')
cl.destroy()
코드에 감사드립니다. 정말 유용했습니다! 나는 또한 다음 라인 프로세스를 구현했다. 그러나 단어를 깨뜨리고 캡션이 자동으로 이미지의 크기를 균일하게 채우기 위해 글꼴 크기를 계산했기 때문에 약간의 연마가 필요하다. 나는 이것도 알아 내야 할 것 같다;) – GionnyBanana
또한 5GB의 여유 디스크 공간과 임시 파일로 많은 양을 먹어서 HD 이미지를 사용하면 스크립트가 다운되는 것을 깨달았습니다. – GionnyBanana
나머지는 알아낼 수 있다고 생각합니다. 그것은 모두 기본 기하학이며, 붙어 있다면 새로운 질문을 게시 할 수 있습니다. HD 이미지의 경우 많은 시간과 리소스가 필요하며 OpenCL/OpenMP 및 HDRI 지원으로 컴파일 된 ImageMagick을 탐색 해 볼 가치가 있습니다. 그러나 솔직히, 나는 위에 열거 된 기본 기능들로 코드 완성이 끝날 때까지 그 문제를 무시할 것이다. – emcconville