Skip to main content

A Python library to create images with customizable text overlays.

Project description

Txt2Img

Txt2Img is a Python library that allows you to add text to an image, either by providing a URL for the background image or by generating a gradient background.

Installation

To install Txt2Img, you can use pip:

pip install opencv-python
pip install requests

Usage

Here's an example of how to use the Txt2Img class:

from Txt2Img import Txt2Img

# Create an instance of the Txt2Img class
img_generator = Txt2Img(
    text="Hello, World!",
    url="https://example.com/background.jpg",
    width=800,
    height=600,
    text_color=(255, 255, 255),  # White text
    text_background_color=(0, 0, 0),  # Black background
    font_scale=2,
    font_thickness=3,
    text_position="center"
)

# Create the image
img_generator.create()

# Show the image
img_generator.show()

# Save the image
img_generator.download()

API

The Txt2Img class has the following methods:

  • __init__(self, text, url=None, width=800, height=600, **kwargs): Initializes the Txt2Img class with the specified parameters.
  • open_image_from_url(self): Downloads the image from the provided URL and returns it as a NumPy array.
  • create_gradient(self): Creates a gradient background image.
  • add_text(self, img): Adds the specified text to the image.
  • create(self): Generates the final image by either opening the image from the URL or creating a gradient background, and then adding the text to the image.
  • show(self): Displays the generated image using OpenCV.
  • download(self): Saves the generated image to a file with the same name as the text.

License

This project is licensed under the MIT License.

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

txttoimg-0.1.1.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

txttoimg-0.1.1-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file txttoimg-0.1.1.tar.gz.

File metadata

  • Download URL: txttoimg-0.1.1.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.6

File hashes

Hashes for txttoimg-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7b3c94a5e5c4cbe9f00c6fe6d39276e79151899806947a87f90a6ef5db6ea99d
MD5 c6f7f24e92f9e2bf28730ccad368440c
BLAKE2b-256 a6c76205505158329cc66920e33f8e9362db7e63d004f73f1ec33439323b5efc

See more details on using hashes here.

File details

Details for the file txttoimg-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: txttoimg-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.6

File hashes

Hashes for txttoimg-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0ea6ed65a8aa7d35cff4c6ebd2b38c7f2da5aefc1ad6c31a20896d5569d310e8
MD5 725179e0e817884bd842f4842ab02526
BLAKE2b-256 a5bbfddfa01a065e0bc9cd98e131b2a6f3ecf2dd7b4e7beb9910f593037aa72c

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