GithubHelp home page GithubHelp logo

pilmoji's Introduction

Pilmoji

Pilmoji is an emoji renderer for Pillow, Python's imaging library.

Pilmoji comes equipped with support for both unicode emojis and Discord emojis.

Features

  • Discord emoji support
  • Multi-line rendering support
  • Emoji position and/or size adjusting
  • Many built-in emoji sources
  • Optional caching

Installation and Requirements

You must have Python 3.8 or higher in order to install Pilmoji.

Installation can be done with pip:

$ pip install -U pilmoji

Optionally, you can add the [requests] option to install requests alongside Pilmoji:

$ pip install -U pilmoji[requests]

The option is not required, instead if requests is not installed, Pilmoji will fallback to use the builtin urllib.

You may also install from Github.

Usage

from pilmoji import Pilmoji
from PIL import Image, ImageFont


my_string = '''
Hello, world! ๐Ÿ‘‹ Here are some emojis: ๐ŸŽจ ๐ŸŒŠ ๐Ÿ˜Ž
I also support Discord emoji: <:rooThink:596576798351949847>
'''

with Image.new('RGB', (550, 80), (255, 255, 255)) as image:
    font = ImageFont.truetype('arial.ttf', 24)

    with Pilmoji(image) as pilmoji:
        pilmoji.text((10, 10), my_string.strip(), (0, 0, 0), font)

    image.show()

Result

Example result

Switching emoji sources

As seen from the example, Pilmoji defaults to the Twemoji emoji source.

If you prefer emojis from a different source, for example Microsoft, simply set the source kwarg in the constructor to a source found in the pilmoji.source module:

from pilmoji.source import MicrosoftEmojiSource

with Pilmoji(image, source=MicrosoftEmojiSource) as pilmoji:
    ...

results

It is also possible to create your own emoji sources via subclass.

Fine adjustments

If an emoji looks too small or too big, or out of place, you can make fine adjustments with the emoji_scale_factor and emoji_position_offset kwargs:

pilmoji.text((10, 10), my_string.strip(), (0, 0, 0), font,
             emoji_scale_factor=1.15, emoji_position_offset=(0, -2))

Contributing

Contributions are welcome. Make sure to follow PEP-8 styling guidelines.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.