How To Render Emojis As Images In Python Under Windows?
My goal is to generate (in Python under Windows) a bitmap image rendering any unicode character, including in particular emojis. I have installed several emoji-friendly fonts (incl
Solution 1:
I eventually found a solution in Is there any good python library for generating and rendering text in image format?. Although it is based on a third-party executable, as mentioned it is easy to wrap in Python.
Exact steps were as follows:
- Install ImageMagick from https://www.imagemagick.org/script/download.php#windows
- Set environment variable
MAGICK_HOME
to installation folder - Install Pillow to be able to manipulate easily the resulting image in Python (
conda install pillow
) - Download and install the Symbola font from https://fontlibrary.org/en/font/symbola
And my test script:
import os
import subprocess
import PIL.Image
to_render = '🤓'
output_file = 'rendered_emoji.bmp'
subprocess.run([
os.path.join(os.environ['MAGICK_HOME'], 'magick.exe'),
'convert', '-font', 'Symbola', '-size', '50x50',
'-gravity', 'center', f'label:{to_render}', output_file])
image = PIL.Image.open(output_file)
image.show()
Post a Comment for "How To Render Emojis As Images In Python Under Windows?"