How can I draw text with different stroke and fill colors on images with python?
Here is some text with red stroke and gray fill.
Using imagemagick:
import subprocess
args = {
'bgColor': 'transparent',
'fgColor': 'light slate grey',
'fgOutlineColor': 'red',
'text': 'Example',
'size': 72,
'geometry': '350x100!',
'output': '/tmp/out.png',
'font': 'helvetica'
}
cmd = ['convert', 'xc:{bgColor}', '-resize', '{geometry}', '-gravity', 'Center',
'-font', '{font}', '-pointsize', '{size}', '-fill', '{fgColor}',
'-stroke', '{fgOutlineColor}', '-draw', "text 0,0 '{text}'", '-trim', '{output}']
cmd = [item.format(**args) for item in cmd]
proc = subprocess.Popen(cmd)
proc.communicate()
