Name | piltext JSON |
Version |
0.2.3
JSON |
| download |
home_page | None |
Summary | Creates PNG from text using Pillow |
upload_time | 2025-02-22 19:37:35 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >3.8.0 |
license | MIT License
Copyright (c) 2024 Holger Nahrstaedt
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
|
keywords |
pillow
png
pil
|
VCS |
 |
bugtrack_url |
|
requirements |
Pillow
|
Travis-CI |
No Travis.
|
coveralls test coverage |
|
# piltext
[](https://codecov.io/gh/holgern/piltext)
[](https://pypi.python.org/pypi/piltext/)
Creates PNG from text using Pillow
### Installation
PyPI
```bash
pip install piltext
```
or from source
```bash
git clone https://github.com/holgern/piltext.git
cd piltext
python3 setup.py install
```
## License
[MIT](https://choosealicense.com/licenses/mit/)
## Usage
Import the import parts
```
from piltext import FontManager, ImageDrawer, TextGrid
```
Download fonts:
```
f = FontManager(default_font_size=20)
font1 = f.download_google_font("ofl", "roboto", "Roboto[wdth,wght].ttf")
font2 = f.download_google_font("ofl", "jersey10", "Jersey10-Regular.ttf")
f.default_font_name = font1
print(f.list_available_fonts())
```
Fonts with variations can be used
```
print(f.get_variation_names())
```
Create image with texts:
```
image = ImageDrawer(100, 100, f)
xy = (0, 0)
w, h, font_size = image.draw_text("Test", xy, font_variation="Bold")
xy = (xy[0], xy[1] + h)
w, h, font_size = image.draw_text("Test", xy)
xy = (xy[0] + w, xy[1])
w, h, font_size = image.draw_text("Test", xy)
xy = (xy[0], xy[1] + h)
w, h, font_size = image.draw_text("Test", xy, font_name=font2, fill=128)
xy = (0, xy[1] + h)
w, h, font_size = image.draw_text(
"Test", xy, end=(100, 100), font_variation="Condensed Medium"
)
print(f"w: {w}, h:{h}, font_size: {font_size}")
image.finalize(inverted=False)
display(image.get_image())
```
Anchor can be used:
```
image = ImageDrawer(480, 280, f)
xy = (5, 3)
w, h, font_size = image.draw_text(
"Long Text 1", xy, end=(480, (280 - 15) / 3), anchor="lt"
)
xy = (5, int(h * 0.85))
w, h, font_size = image.draw_text(
"Long Text 2", xy, end=(480, xy[1] * 1.5), anchor="lt"
)
xy = (5, xy[1] + h)
w, h, font_size = image.draw_text(
"Long Text 3", xy, font_size=font_size, font_variation="Thin", anchor="lt"
)
xy = (5, xy[1] + h)
w, h, font_size = image.draw_text("Long Text 3", xy, font_size=font_size, anchor="lt")
w, h, font_size = image.draw_text(
"Long Text 4", (480 - 5, 280 - 5), end=(5, 5), anchor="rs"
)
image.finalize(inverted=False)
display(image.get_image())
```
TextGrid
```
image = ImageDrawer(480, 280, f)
grid = TextGrid(7, 4, image, margin_x=2, margin_y=2)
grid.print_grid()
merge_list = [
((0, 0), (0, 3)),
((1, 0), (2, 1)),
((1, 2), (2, 3)),
((3, 0), (6, 3)),
]
grid.merge_bulk(merge_list)
grid.print_grid()
```
can be used to improve text layout:
```
image.initialize()
grid.set_text(0, "Test1", font_name=font2)
grid.set_text(1, "Test2")
grid.set_text(2, "Test3")
grid.set_text(3, "Test4", anchor="lt")
image.finalize(inverted=False)
display(image.get_image())
```
The text can also be set as bulk using a list:
```
image.initialize()
text_list = [
{"start": 0, "text": "Test1", "font_name": font2},
{"start": 1, "text": "Test2"},
{"start": 2, "text": "Test3"},
{"start": 3, "text": "Test4", "anchor": "lt", "fill": 128},
]
grid.set_text_list(text_list)
image.finalize(inverted=False)
display(image.get_image())
```
## Pre-commit-config
### Installation
```
$ pip install pre-commit
```
### Using homebrew:
```
$ brew install pre-commit
```
```
$ pre-commit --version
pre-commit 2.10.0
```
### Install the git hook scripts
```
$ pre-commit install
```
### Run against all the files
```
pre-commit run --all-files
pre-commit run --show-diff-on-failure --color=always --all-files
```
### Update package rev in pre-commit yaml
```bash
pre-commit autoupdate
pre-commit run --show-diff-on-failure --color=always --all-files
```
Raw data
{
"_id": null,
"home_page": null,
"name": "piltext",
"maintainer": null,
"docs_url": null,
"requires_python": ">3.8.0",
"maintainer_email": null,
"keywords": "Pillow, png, PIL",
"author": null,
"author_email": "Holger Nahrstaedt <nahrstaedt@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/4b/e3/ea1cc0254f459ba45efed4afbbf146402479362a4e8541f87bdb23df3cf3/piltext-0.2.3.tar.gz",
"platform": null,
"description": "# piltext\n\n[](https://codecov.io/gh/holgern/piltext)\n[](https://pypi.python.org/pypi/piltext/)\n\nCreates PNG from text using Pillow\n\n### Installation\n\nPyPI\n\n```bash\npip install piltext\n```\n\nor from source\n\n```bash\ngit clone https://github.com/holgern/piltext.git\ncd piltext\npython3 setup.py install\n```\n\n## License\n\n[MIT](https://choosealicense.com/licenses/mit/)\n\n## Usage\n\nImport the import parts\n\n```\nfrom piltext import FontManager, ImageDrawer, TextGrid\n```\n\nDownload fonts:\n\n```\nf = FontManager(default_font_size=20)\nfont1 = f.download_google_font(\"ofl\", \"roboto\", \"Roboto[wdth,wght].ttf\")\nfont2 = f.download_google_font(\"ofl\", \"jersey10\", \"Jersey10-Regular.ttf\")\nf.default_font_name = font1\nprint(f.list_available_fonts())\n```\n\nFonts with variations can be used\n\n```\nprint(f.get_variation_names())\n```\n\nCreate image with texts:\n\n```\nimage = ImageDrawer(100, 100, f)\nxy = (0, 0)\nw, h, font_size = image.draw_text(\"Test\", xy, font_variation=\"Bold\")\nxy = (xy[0], xy[1] + h)\nw, h, font_size = image.draw_text(\"Test\", xy)\nxy = (xy[0] + w, xy[1])\nw, h, font_size = image.draw_text(\"Test\", xy)\nxy = (xy[0], xy[1] + h)\nw, h, font_size = image.draw_text(\"Test\", xy, font_name=font2, fill=128)\nxy = (0, xy[1] + h)\nw, h, font_size = image.draw_text(\n \"Test\", xy, end=(100, 100), font_variation=\"Condensed Medium\"\n)\nprint(f\"w: {w}, h:{h}, font_size: {font_size}\")\n\nimage.finalize(inverted=False)\ndisplay(image.get_image())\n```\n\nAnchor can be used:\n\n```\nimage = ImageDrawer(480, 280, f)\nxy = (5, 3)\nw, h, font_size = image.draw_text(\n \"Long Text 1\", xy, end=(480, (280 - 15) / 3), anchor=\"lt\"\n)\nxy = (5, int(h * 0.85))\nw, h, font_size = image.draw_text(\n \"Long Text 2\", xy, end=(480, xy[1] * 1.5), anchor=\"lt\"\n)\nxy = (5, xy[1] + h)\nw, h, font_size = image.draw_text(\n \"Long Text 3\", xy, font_size=font_size, font_variation=\"Thin\", anchor=\"lt\"\n)\nxy = (5, xy[1] + h)\nw, h, font_size = image.draw_text(\"Long Text 3\", xy, font_size=font_size, anchor=\"lt\")\nw, h, font_size = image.draw_text(\n \"Long Text 4\", (480 - 5, 280 - 5), end=(5, 5), anchor=\"rs\"\n)\n\nimage.finalize(inverted=False)\ndisplay(image.get_image())\n```\n\nTextGrid\n\n```\nimage = ImageDrawer(480, 280, f)\n\ngrid = TextGrid(7, 4, image, margin_x=2, margin_y=2)\ngrid.print_grid()\nmerge_list = [\n ((0, 0), (0, 3)),\n ((1, 0), (2, 1)),\n ((1, 2), (2, 3)),\n ((3, 0), (6, 3)),\n]\ngrid.merge_bulk(merge_list)\ngrid.print_grid()\n```\n\ncan be used to improve text layout:\n\n```\nimage.initialize()\ngrid.set_text(0, \"Test1\", font_name=font2)\ngrid.set_text(1, \"Test2\")\ngrid.set_text(2, \"Test3\")\ngrid.set_text(3, \"Test4\", anchor=\"lt\")\nimage.finalize(inverted=False)\ndisplay(image.get_image())\n```\n\nThe text can also be set as bulk using a list:\n\n```\nimage.initialize()\ntext_list = [\n {\"start\": 0, \"text\": \"Test1\", \"font_name\": font2},\n {\"start\": 1, \"text\": \"Test2\"},\n {\"start\": 2, \"text\": \"Test3\"},\n {\"start\": 3, \"text\": \"Test4\", \"anchor\": \"lt\", \"fill\": 128},\n]\ngrid.set_text_list(text_list)\nimage.finalize(inverted=False)\ndisplay(image.get_image())\n```\n\n## Pre-commit-config\n\n### Installation\n\n```\n$ pip install pre-commit\n```\n\n### Using homebrew:\n\n```\n$ brew install pre-commit\n```\n\n```\n$ pre-commit --version\npre-commit 2.10.0\n```\n\n### Install the git hook scripts\n\n```\n$ pre-commit install\n```\n\n### Run against all the files\n\n```\npre-commit run --all-files\npre-commit run --show-diff-on-failure --color=always --all-files\n```\n\n### Update package rev in pre-commit yaml\n\n```bash\npre-commit autoupdate\npre-commit run --show-diff-on-failure --color=always --all-files\n```\n",
"bugtrack_url": null,
"license": "MIT License\n \n Copyright (c) 2024 Holger Nahrstaedt\n \n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n \n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n \n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n ",
"summary": "Creates PNG from text using Pillow",
"version": "0.2.3",
"project_urls": {
"Homepage": "https://github.com/holgern/piltext"
},
"split_keywords": [
"pillow",
" png",
" pil"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "2b882c38e1e4f553b6b81c371e8ed74e0fc93fff56e631b6f68cbdd9be68ca04",
"md5": "fe2a6586238608c482afaadd7bd9d297",
"sha256": "bf858b3e8a7a49a33a4e86c8bba9077e9192ba4ca3e81f764a15b0909af3a75e"
},
"downloads": -1,
"filename": "piltext-0.2.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "fe2a6586238608c482afaadd7bd9d297",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">3.8.0",
"size": 11208,
"upload_time": "2025-02-22T19:37:34",
"upload_time_iso_8601": "2025-02-22T19:37:34.396661Z",
"url": "https://files.pythonhosted.org/packages/2b/88/2c38e1e4f553b6b81c371e8ed74e0fc93fff56e631b6f68cbdd9be68ca04/piltext-0.2.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "4be3ea1cc0254f459ba45efed4afbbf146402479362a4e8541f87bdb23df3cf3",
"md5": "14a3bbb799e28cfd30cede5218c76169",
"sha256": "d2af78746944709b289299955f08f15dd626e6c59ac8ed74825fa6c2a60670a5"
},
"downloads": -1,
"filename": "piltext-0.2.3.tar.gz",
"has_sig": false,
"md5_digest": "14a3bbb799e28cfd30cede5218c76169",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">3.8.0",
"size": 217710,
"upload_time": "2025-02-22T19:37:35",
"upload_time_iso_8601": "2025-02-22T19:37:35.993153Z",
"url": "https://files.pythonhosted.org/packages/4b/e3/ea1cc0254f459ba45efed4afbbf146402479362a4e8541f87bdb23df3cf3/piltext-0.2.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-22 19:37:35",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "holgern",
"github_project": "piltext",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"requirements": [
{
"name": "Pillow",
"specs": []
}
],
"lcname": "piltext"
}