Search code examples
pythonpython-imaging-libraryemoji

How to download Noto Color Emoji into PNG


I would like to pick any of the emoji in the following site, select the resolution and download it into PNG image whith transparent background. However I could not find any way to do this systematiccaly since I would need to do for a few emojis.

can you recommend how this can be achieved?

https://fonts.google.com/noto/specimen/Noto+Color+Emoji/glyphs

I tried using some libraries like PIL where I provide the emoji directly. But this doesn't really work well and if I achieve to download the picture, the emoji it is shown in bad way (the layout and shape is not so nice as the once I can see on the page above). So I would like to be able to download exactly with the cool style I can see on website above


Solution

  • Pillow (version 10) mostly works for me; it needs a bit of hand-holding but gets there in the end. Note that I've got these fonts installed system-wide, you might need to download them and update the path appropriately.

    from PIL import Image, ImageDraw, ImageFont
    
    # see https://github.com/python-pillow/Pillow/issues/3346 for "size=109"
    noto = ImageFont.truetype(
        '/usr/share/fonts/noto/NotoColorEmoji.ttf',
        size=109,
    )
    
    text = "😅🥳🎉"
    bbox = noto.getbbox(text)
    
    im = Image.new('RGBA', bbox[2:])
    draw = ImageDraw.Draw(im)
    draw.text((0,0), text, font=noto, embedded_color=True)
    im.save('emoji.png')
    

    Which results in the following PNG being saved:

    PIL Output