Skip to main content

An asynchronous, template-based image generation engine

Project description

AlphaPIL

About

AlphaPIL is an asynchronous, template-based image generation engine built on top of Pillow (PIL). It is designed to make it easy to build dynamic images using a simple, readable template language.

It is open-source and free to use, providing a powerful recursive parser for handling nested functions in image generation templates, with full support for asynchronous operations.

AlphaPIL is suitable for developers building Discord bots, automated social media graphics, or any application requiring high-performance, template-driven image creation. This package is proudly maintained by the MeraLabs organization.

Features

  • 60+ Pre-built Functions: AlphaPIL comes packed with over 60 pre-built functions for shapes, text manipulation, image filtering, and masking.
  • Asynchronous by Design: Built from the ground up to support asyncio, making it perfect for modern web frameworks and Discord bots.
  • Powerful DSL: Use a simple $function[arg1;arg2] syntax to define your images. Supports nested functions like $drawText[$toUpper[hello];10;10].
  • Advanced Text Rendering: Support for text gradients, strokes, automatic wrapping, and auto-sizing.
  • Layer & Masking System: Create complex compositions with multi-layer support and alpha masking.
  • Image Caching: Built-in caching for remote images to ensure fast rendering during repeated operations.

Setup

Install AlphaPIL via pip:

pip install alphapil

Basic usage in your Python project:

import asyncio
from alphapil import CanvasEngine

async def main():
    engine = CanvasEngine()
    
    template = """
    $createCanvas[800;400;#1a1a1a]
    $setColor[#ffffff]
    $setFont[Arial;40]
    $drawText[Hello from AlphaPIL!;50;50]
    $save[output.png]
    """
    
    await engine.render_template(template)
    print("Image generated successfully!")

asyncio.run(main())

Rendering with Data

You can inject dynamic data into your templates easily:

data = {
    "username": "Alex",
    "score": "950"
}

template = """
$createCanvas[500;200;white]
$setColor[black]
$setFont[Roboto;30]
$drawText[User: {username};20;20]
$drawText[Score: {score};20;60]
"""

image_bytes = await engine.render_template(template, data=data)

Advanced Masking

AlphaPIL supports complex masking for creating avatars or stylized images:

template = """
$createCanvas[400;400;transparent]
$createLayer[mask]
$drawCircle[200;200;180;white]
$switchLayer[main]
$drawImage[https://example.com/avatar.png;0;0;400;400]
$applyMask[mask]
"""

🎯 Interactive Coordinate Picker

To make designing templates easier, AlphaPIL comes with a premium Interactive Coordinate Picker Web GUI!

  • Hover your mouse to see precise pixel coordinates in real-time with an alignment reticle.
  • Click anywhere on the image to copy coordinates (formatted as x;y ready for pasting into your templates).
  • Drag and drop other generated images directly to inspect them.

Option A: Open from Terminal (CLI)

Once installed, you can launch the picker directly from your command line:

alphapil-picker output.png

Option B: Launch from Python Script

You can open the picker directly from your Python rendering script:

from alphapil import open_coordinate_picker

# Instantly opens your browser displaying output.png
open_coordinate_picker("output.png")

Support

Need help? Join our official Discord community for support and updates! Join MeraLabs Discord

Contributing

Refer to the Contribution Documentation for more information.

Keywords

alphapil image-generation pillow python async discord-bot template-engine meralabs canvas dsl

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

alphapil-0.3.6.tar.gz (56.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

alphapil-0.3.6-py3-none-any.whl (60.7 kB view details)

Uploaded Python 3

File details

Details for the file alphapil-0.3.6.tar.gz.

File metadata

  • Download URL: alphapil-0.3.6.tar.gz
  • Upload date:
  • Size: 56.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for alphapil-0.3.6.tar.gz
Algorithm Hash digest
SHA256 32516ae021ebd04251f46551ae4362a7b36abf0adce8978aef54de54ea0d92f9
MD5 253bc0bad8c6eddc32d22da3d6676792
BLAKE2b-256 e95bb709fae2de2c59c35b7d7488c284739064aaab18c68d0bdb58058c54ffe7

See more details on using hashes here.

File details

Details for the file alphapil-0.3.6-py3-none-any.whl.

File metadata

  • Download URL: alphapil-0.3.6-py3-none-any.whl
  • Upload date:
  • Size: 60.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for alphapil-0.3.6-py3-none-any.whl
Algorithm Hash digest
SHA256 ec030ad50f62ebe2da8971e276c14922270ec7dfa14bdc2dfc4295cccf3d3429
MD5 6ae542421a83119c99ffe976ce2a2096
BLAKE2b-256 f2b9f095b1851471d856ffdd9d40cf3fc5b717960b94954777aa7ca30c04a8a1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page