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.0.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.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: txttoimg-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 3feddaa86fe13abc8d8ebaf604328d4d393c9c40c8f068d4a97855be0b2807be
MD5 177a15807ed9aa7c11c33f2b019d45ba
BLAKE2b-256 aba7725cb78119d3fd6303865ba33749d1fd18eadad79fa509639e9c6b1db58a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: txttoimg-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.2 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c9a3b845a944de957cbeffd81095aee2a47b6923a42cb491a68b2e0d747c208e
MD5 1a36ab4f89a227d35f0926b0b90fd56f
BLAKE2b-256 0025e98ff143e7306dcb817c5e3dc1455d3d30db8aff0c9272df7a996f8ec94a

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