- Saved searches
- Use saved searches to filter your results more quickly
- License
- akapila011/Text-to-Image
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
- text-to-image 0.0.5
- Requirements
- Install
- How to Use
- Tests
- Convert Text to PNG, JPEG, or GIF Image in Python
- Python Library to Convert Text to Image#
- How to Convert Text to Image in Python#
- Free Python Text to Image Converter#
- Conclusion#
- See Also#
- destan / text2png.py
- Example
- История выпусков Уведомления о выпусках | Лента RSS
- Загрузка файлов
- Source Distribution
- Built Distribution
- Хеши для text2png-0.5.0.tar.gz
- Хеши для text2png-0.5.0-py3-none-any.whl
- Помощь
- О PyPI
- Внесение вклада в PyPI
- Использование PyPI
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Convert your text to a grayscale image and back.
License
akapila011/Text-to-Image
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
Easily convert your text to grayscale images and vice versa.
With this tool you can encode text or plain text files to a grayscale image to be easily shared. Each pixel represents a single character’s decimal value. When decoding an image you can decode text straight to the console or to a plain text file.
Images use a PNG file extension. The image size will be automatically be set depending on the text length to be encoded.
Text should use a character encoding scheme using 8 bits or less until additional functionality is added to support UTF-8 (16 bit). If a character’s decimal value is greater than the limit (see below) the it will be divided by the limit and the new value used. When the character value equals the limit value the new value will be 1.
The limit value passed using either command line argument -l(—limit) specifies the decimal value limit for pixel values starting from 1. The default is 256 allowing for numbers from 1 to 255 (i.e. 8 bit pixels). If the limit value is greater than 8 bits then the value will still be wrapped around since the output image is grayscale.
You can install text_to_image using pip or setup.py
$> pip3 install text_to_image
Once installed you can either directly use the encode.py and decode.py file or import and use the relevant functions.
$> python3 encode.py -t "Hello World!" image.png # encodes given text $> python3 encode.py -f my-text-file.txt image.png # encodes a text file $> python3 encode.py --help # for more information on arguments
$> python3 decode.py image.png # decodes a given image $> python3 decode.py -f my-text-file.txt image.png # decodes image.png to the given text file $> python3 decode.py --help # for more information on arguments
import text_to_image encoded_image_path = text_to_image.encode("Hello World!", "image.png") encoded_image_path = text_to_image.encode_file("input_text_file.txt", "output_image.png") decoded_text = text_to_image.decode("encoded_image.png") decoded_file_path = text_to_image.decode_to_file("encoded_image.png", "output_text_file.txt")
To run tests, navigate to the root directory where setup.py is located and run
$> python3-m unittest discover tests -v
About
Convert your text to a grayscale image and back.
text-to-image 0.0.5
Easily convert your text to grayscale images and vice versa.
With this tool you can encode text or plain text files to a grayscale image to be easily shared. Each pixel represents a single character’s decimal value. When decoding an image you can decode text straight to the console or to a plain text file.
Images use a PNG file extension. The image size will be automatically be set depending on the text length to be encoded.
Text should use a character encoding scheme using 8 bits or less until additional functionality is added to support UTF-8 (16 bit). If a character’s decimal value is greater than the limit (see below) the it will be divided by the limit and the new value used. When the character value equals the limit value the new value will be 1.
The limit value passed using either command line argument -l(–limit) specifies the decimal value limit for pixel values starting from 1. The default is 256 allowing for numbers from 0 to 255 (i.e. 8 bit pixels). If the limit value is greater than 8 bits then the value will still be wrapped around since the output image is grayscale.
Requirements
Install
You can install text_to_image using pip or setup.py
$> pip3 install text_to_image
How to Use
Once installed you can either directly use the encode.py and decode.py file or import and use the relevant functions.
$> python3 encode.py -t image.png $> python3 encode.py -f my-text-file.txt image.png $> python3 encode.py --help
$> python3 decode.py image.png $> python3 decode.py -f my-text-file.txt image.png $> python3 decode.py --help
Tests
To run tests, navigate to the root directory where setup.py is located and run
$> python3-m unittest discover tests -v
TODO:
Convert Text to PNG, JPEG, or GIF Image in Python
As a Python developer, you may need text to image conversion in various cases, such as to make the text read-only, to render text, etc. If you are dealing with such a scenario, this article is going to provide you with a free, high-speed and high-quality text to image conversion solution for Python. So let’s see how to convert text to PNG, JPG, or GIF images in Python.
Python Library to Convert Text to Image#
To convert text to images, we will use Aspose.Words for Python. It is a powerful Python library that lets you create and manipulate text documents seamlessly. You can install the library in your Python application from PyPI using the following pip command.
How to Convert Text to Image in Python#
TXT files provide the simplest and easiest way to store plain text without any formatting. Therefore, we will use a TXT file and convert its text into PNG, JPEG, or GIF images.
The following are the steps to convert text to images in Python.
- Load the text file using the Document class.
- Loop through all the pages in the document.
- Extract each page using Document.extract_pages() method.
- Save page as PNG (or another image format) using Document.save() method.
The following code sample shows how to perform text to image conversion in Python.
Free Python Text to Image Converter#
You can get a free temporary license to convert text to image without evaluation limitations.
Conclusion#
In this article, you have learned how to convert text to image programmatically in Python. You can simply install the library and use the provided code sample to convert the text to PNG, JPEG, or GIF images. In addition, you can learn more about the library using the documentation. Also, you can share your questions or queries via our forum.
See Also#
destan / text2png.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
# coding=utf8 |
import PIL |
from PIL import ImageFont |
from PIL import Image |
from PIL import ImageDraw |
def text2png ( text , fullpath , color = «#000» , bgcolor = «#FFF» , fontfullpath = None , fontsize = 13 , leftpadding = 3 , rightpadding = 3 , width = 200 ): |
REPLACEMENT_CHARACTER = u’ \uFFFD ‘ |
NEWLINE_REPLACEMENT_STRING = ‘ ‘ + REPLACEMENT_CHARACTER + ‘ ‘ |
#prepare linkback |
linkback = «created via http://ourdomain.com» |
fontlinkback = ImageFont . truetype ( ‘font.ttf’ , 8 ) |
linkbackx = fontlinkback . getsize ( linkback )[ 0 ] |
linkback_height = fontlinkback . getsize ( linkback )[ 1 ] |
#end of linkback |
font = ImageFont . load_default () if fontfullpath == None else ImageFont . truetype ( fontfullpath , fontsize ) |
text = text . replace ( ‘ \n ‘ , NEWLINE_REPLACEMENT_STRING ) |
lines = [] |
line = u»» |
for word in text . split (): |
print word |
if word == REPLACEMENT_CHARACTER : #give a blank line |
lines . append ( line [ 1 :] ) #slice the white space in the begining of the line |
line = u»» |
lines . append ( u»» ) #the blank line |
elif font . getsize ( line + ‘ ‘ + word )[ 0 ] |
line += ‘ ‘ + word |
else : #start a new line |
lines . append ( line [ 1 :] ) #slice the white space in the begining of the line |
line = u»» |
#TODO: handle too long words at this point |
line += ‘ ‘ + word #for now, assume no word alone can exceed the line width |
if len ( line ) != 0 : |
lines . append ( line [ 1 :] ) #add the last line |
line_height = font . getsize ( text )[ 1 ] |
img_height = line_height * ( len ( lines ) + 1 ) |
img = Image . new ( «RGBA» , ( width , img_height ), bgcolor ) |
draw = ImageDraw . Draw ( img ) |
y = 0 |
for line in lines : |
draw . text ( ( leftpadding , y ), line , color , font = font ) |
y += line_height |
# add linkback at the bottom |
draw . text ( ( width — linkbackx , img_height — linkback_height ), linkback , color , font = fontlinkback ) |
img . save ( fullpath ) |
#show time |
text2png ( u»This is \n a \n test şğıöç zaa xd ve lorem hipster» , ‘test.png’ , fontfullpath = «font.ttf» ) |
Example
История выпусков Уведомления о выпусках | Лента RSS
Загрузка файлов
Загрузите файл для вашей платформы. Если вы не уверены, какой выбрать, узнайте больше об установке пакетов.
Source Distribution
Uploaded 14 окт. 2021 г. source
Built Distribution
Uploaded 14 окт. 2021 г. py3
Хеши для text2png-0.5.0.tar.gz
Алгоритм | Хеш-дайджест | |
---|---|---|
SHA256 | ee38dc54446b7026c8e34ff06d3f890016a77cd9094040297e86743a39ab0b80 | Копировать |
MD5 | 26fa7975212cbbf46fa370f42915b256 | Копировать |
BLAKE2b-256 | 4c6c885e412a2d2ffe9903209353f570e5f94f59d624489034c556b8d94aa96b | Копировать |
Хеши для text2png-0.5.0-py3-none-any.whl
Алгоритм | Хеш-дайджест | |
---|---|---|
SHA256 | 1c9a32d21523ac817e353864cca5a44bb26dc6e7c2773eded4edaec73dfc8695 | Копировать |
MD5 | 58aa3c86f69ba9db345d37dea1498de7 | Копировать |
BLAKE2b-256 | 1eb99fa4775ff6eb71e9355f52e72707aeff78f475c0daf736c18658ccc42677 | Копировать |
Помощь
О PyPI
Внесение вклада в PyPI
Использование PyPI
Разработано и поддерживается сообществом Python’а для сообщества Python’а.
Пожертвуйте сегодня!
PyPI», «Python Package Index» и логотипы блоков являются зарегистрированными товарными знаками Python Software Foundation.