Welcome to the Text to Image API, a simple Flask-based API that allows you to generate images from text, add text to existing images, and more. This API is designed to be easy to use and integrate into your applications.
Note
if you want to integrate this api into you personal or commercial projects I'll recommend you deploy the api rather than use e publicly available one.
- Convert text into images with customizable fonts, sizes, colors, and alignment.
- Add text overlays to existing images.
- Caching for improved performance.
- Python 3.x
- Other depedencies in the requirements.txt
-
Clone the repository:
git clone https://github.com/DannyAkintunde/TextArtify.git cd TextArtify -
Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install the required packages:
pip install -r requirements.txt
-
Run the application:
flask run
The API will be available at http://127.0.0.1:5000.
You can interact with the API using tools like Postman or cURL. Below are the available endpoints.
Endpoint: /api/v1/text-to-image
Method: GET or POST
Parameters:
text(required): The text to be converted into an image.font: The font to use (optional).font_size: The size of the font (default: 52).color: The text color in hex format (default:#FFFFFFFF).bg_color: The background color in hex format (default:#000000FF).min_size: Minimum size of the image (optional).max_size: Maximum size of the image (optional).text_align: Alignment of the text (optional, can becenter,left, orright).padding_ratio: Padding ratio for the text (default: 0.1).
Example Request:
curl -X POST "http://127.0.0.1:5000/api/v1/text-to-image" -H "Content-Type: application/json" -d '{"text": "Hello World", "font": "arimo-bold-italic"}' -o out.pngEndpoint: /api/v1/add-text-to-img
Method: GET or POST
Parameters:
text(required): The text to overlay on the image.bg(required): URL of the background image.font: The font to use (optional).font_size: The size of the font (default: 52).color: The text color in hex format (default:#FFFFFFFF).text_align: Alignment of the text (optional, can becenter,left, orright).padding_ratio: Padding ratio for the text (default: 0.1).
Example Request:
curl -X POST "http://127.0.0.1:5000/api/v1/add-text-to-img" -H "Content-Type: application/json" -d '{"text": "Sample Text", "bg": "https://example.com/image.jpg"}'These are the currently supported fonts
- arimo
- arimo-regular
- arimo-italic
- arimo-bold
- arimo-bold-italic
- arimo-medium
- arimo-medium-italic
- arimo-semibold
- arimo-semibold-italic
- arizonia
- arizonia-regular
to use any of this fonts just add it to the font param in your request
Example Request:
curl -X POST "http://127.0.0.1:5000/api/v1/text-to-image" -H "Content-Type: application/json" -d '{"text": "Hello World", "font": "arizonia-regular"}' -o out.pngLogging is configured to log messages at the INFO level. Errors and warnings are logged appropriately to help with debugging.
Deploy your personal TextArtify server for more control.
Contributions are welcome! Please fork the repository and submit a pull request with your changes.
This project is licensed under the MIT License - see the LICENSE file for details.