CliRenderer


NameCliRenderer JSON
Version 0.1.6.post4 PyPI version JSON
download
home_page
SummaryA CLI tool to render unicode art in the terminal
upload_time2023-08-14 13:26:17
maintainer
docs_urlNone
author
requires_python>=3.9
licenseMIT License Copyright (c) 2023 ultraflame4 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 cli unicode art render terminal
VCS
bugtrack_url
requirements numpy Pillow rich typer imageio numba validators
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # CliRenderer

A text renderer that renders unicode art from images to the terminal

## Installation
**Install the latest version with**: `pip install CliRenderer`

## Usage
See `clirender --help` for a list of options and arguments.

### Notice when reading output

#### Linux
cat the contents like this
`cat outfile`

#### Windows Powershell
cat the contents like this
`Get-Content outfile -encoding UTF8`

This is because the contents of the output files will be encoded in utf-8. powershell defaults to utf-7 for some reason.

----
## Example Outputs:
![img.png](resources/img.png)
[Original image from pexels](https://www.pexels.com/photo/view-of-high-rise-buildings-during-day-time-302769/)

![img.png](resources/img2.png)
[Original image from pexels](https://www.pexels.com/photo/dock-under-cloudy-sky-in-front-of-mountain-206359/)

## How It Works

### Disclaimer
I am terrible at explaining things.

----

This program mainly relies on unicode braille characters to represent pixels.

Braille characters are basically a 2x4 grid of dot(s).

First, I grayscale the image, this is important for later,

then I basically divided the image into many cells of 2x4 pixels width and height.

After because each image cell consists of 2x4 pixels that is grayscale, I can easily find the middle color.
Cycling through the cell, we can now convert the pixels into binary.
Pixel in the cell that are darker than the middle will be False
Pixels that are lighter wil be True
Now we have a boolean array representing bits.

The table below represent how each pixel in the cell correspond to its position in the array.
| 1 | 5 |
|---|---|
| 2 | 6 |
| 3 | 7 |
| 4 | 8 |

Coincidentally, braille characters are ordered the similarly in unicode.
| 1 | 4 |
|---|---|
| 2 | 5 |
| 3 | 6 |
| 7 | 8 |

However, for some reason, 7 is inserted before 4.

So we can just account for that by rearranging the array before converting it into binary like so:
```python
#pixels is the boolean array
converted = [pixels[7], pixels[3], pixels[6], pixels[5], pixels[4], pixels[2], pixels[1], pixels[0]]
```

After converting the array into binary, the binary is the index of the character in the string we need.

#### Coloring

During the process above, another image is generated, we call this a mask,

where it is white, the pixel will be represented by the braille character.

where it is black, the pixel will be represented by the background color.

We once again divide the image up into cells,

iterating through the pixels in the cells, we set 2 colors for each cell: fore and back.

The fore color is calculated by averaging the color from the image where pixel in the mask is white.

The back color is calculated by similarily but using where the pixel in the mask is black.

Then using [rich.py](https://github.com/Textualize/rich), we can color the foreground and background of each character using the fore and back character of each cell.

### More characters
braille characters unfortunately do not really take up the entire character space given to them.

This makes less noticeable, however we can subsitute some of the braille characters to give them more "weight".

For example, I replaced "⣀" with "▂".





            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "CliRenderer",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "cli,unicode,art,render,terminal",
    "author": "",
    "author_email": "ultraflame4 <ultraflame4@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/10/12/2caaba7cb84adb6a571a69384da361187042aaf22197d5af257c5947d278/CliRenderer-0.1.6.post4.tar.gz",
    "platform": null,
    "description": "# CliRenderer\n\nA text renderer that renders unicode art from images to the terminal\n\n## Installation\n**Install the latest version with**: `pip install CliRenderer`\n\n## Usage\nSee `clirender --help` for a list of options and arguments.\n\n### Notice when reading output\n\n#### Linux\ncat the contents like this\n`cat outfile`\n\n#### Windows Powershell\ncat the contents like this\n`Get-Content outfile -encoding UTF8`\n\nThis is because the contents of the output files will be encoded in utf-8. powershell defaults to utf-7 for some reason.\n\n----\n## Example Outputs:\n![img.png](resources/img.png)\n[Original image from pexels](https://www.pexels.com/photo/view-of-high-rise-buildings-during-day-time-302769/)\n\n![img.png](resources/img2.png)\n[Original image from pexels](https://www.pexels.com/photo/dock-under-cloudy-sky-in-front-of-mountain-206359/)\n\n## How It Works\n\n### Disclaimer\nI am terrible at explaining things.\n\n----\n\nThis program mainly relies on unicode braille characters to represent pixels.\n\nBraille characters are basically a 2x4 grid of dot(s).\n\nFirst, I grayscale the image, this is important for later,\n\nthen I basically divided the image into many cells of 2x4 pixels width and height.\n\nAfter because each image cell consists of 2x4 pixels that is grayscale, I can easily find the middle color.\nCycling through the cell, we can now convert the pixels into binary.\nPixel in the cell that are darker than the middle will be False\nPixels that are lighter wil be True\nNow we have a boolean array representing bits.\n\nThe table below represent how each pixel in the cell correspond to its position in the array.\n| 1 | 5 |\n|---|---|\n| 2 | 6 |\n| 3 | 7 |\n| 4 | 8 |\n\nCoincidentally, braille characters are ordered the similarly in unicode.\n| 1 | 4 |\n|---|---|\n| 2 | 5 |\n| 3 | 6 |\n| 7 | 8 |\n\nHowever, for some reason, 7 is inserted before 4.\n\nSo we can just account for that by rearranging the array before converting it into binary like so:\n```python\n#pixels is the boolean array\nconverted = [pixels[7], pixels[3], pixels[6], pixels[5], pixels[4], pixels[2], pixels[1], pixels[0]]\n```\n\nAfter converting the array into binary, the binary is the index of the character in the string we need.\n\n#### Coloring\n\nDuring the process above, another image is generated, we call this a mask,\n\nwhere it is white, the pixel will be represented by the braille character.\n\nwhere it is black, the pixel will be represented by the background color.\n\nWe once again divide the image up into cells,\n\niterating through the pixels in the cells, we set 2 colors for each cell: fore and back.\n\nThe fore color is calculated by averaging the color from the image where pixel in the mask is white.\n\nThe back color is calculated by similarily but using where the pixel in the mask is black.\n\nThen using [rich.py](https://github.com/Textualize/rich), we can color the foreground and background of each character using the fore and back character of each cell.\n\n### More characters\nbraille characters unfortunately do not really take up the entire character space given to them.\n\nThis makes less noticeable, however we can subsitute some of the braille characters to give them more \"weight\".\n\nFor example, I replaced \"\u28c0\" with \"\u2582\".\n\n\n\n\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 ultraflame4  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.",
    "summary": "A CLI tool to render unicode art in the terminal",
    "version": "0.1.6.post4",
    "project_urls": {
        "Bug Tracker": "https://github.com/ultraflame4/CliR/issues",
        "Homepage": "https://github.com/ultraflame4/CliR"
    },
    "split_keywords": [
        "cli",
        "unicode",
        "art",
        "render",
        "terminal"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0c43ef5c21faf628c293a1d14c7639eb3d94960d2176c8f63117ae892ec774e2",
                "md5": "67336b49a7ae6c63098f713b9d232484",
                "sha256": "ae5d201b25a170e2925b4321b893074f74849d479b7f7e9a4f36bd02e408ed08"
            },
            "downloads": -1,
            "filename": "CliRenderer-0.1.6.post4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "67336b49a7ae6c63098f713b9d232484",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 10241,
            "upload_time": "2023-08-14T13:26:15",
            "upload_time_iso_8601": "2023-08-14T13:26:15.897932Z",
            "url": "https://files.pythonhosted.org/packages/0c/43/ef5c21faf628c293a1d14c7639eb3d94960d2176c8f63117ae892ec774e2/CliRenderer-0.1.6.post4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "10122caaba7cb84adb6a571a69384da361187042aaf22197d5af257c5947d278",
                "md5": "81123d1bbdb98d2183ea49dbc5733654",
                "sha256": "772b99e39a7ef444a94c3bcd9a0d594d2513ef7bad77a02e535de03ecd2bce98"
            },
            "downloads": -1,
            "filename": "CliRenderer-0.1.6.post4.tar.gz",
            "has_sig": false,
            "md5_digest": "81123d1bbdb98d2183ea49dbc5733654",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 8840,
            "upload_time": "2023-08-14T13:26:17",
            "upload_time_iso_8601": "2023-08-14T13:26:17.662312Z",
            "url": "https://files.pythonhosted.org/packages/10/12/2caaba7cb84adb6a571a69384da361187042aaf22197d5af257c5947d278/CliRenderer-0.1.6.post4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-14 13:26:17",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ultraflame4",
    "github_project": "CliR",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "numpy",
            "specs": [
                [
                    "~=",
                    "1.24.2"
                ]
            ]
        },
        {
            "name": "Pillow",
            "specs": [
                [
                    "~=",
                    "9.5.0"
                ]
            ]
        },
        {
            "name": "rich",
            "specs": [
                [
                    "~=",
                    "13.3.4"
                ]
            ]
        },
        {
            "name": "typer",
            "specs": [
                [
                    "~=",
                    "0.9.0"
                ]
            ]
        },
        {
            "name": "imageio",
            "specs": [
                [
                    "~=",
                    "2.27.0"
                ]
            ]
        },
        {
            "name": "numba",
            "specs": [
                [
                    "~=",
                    "0.57.0"
                ]
            ]
        },
        {
            "name": "validators",
            "specs": [
                [
                    "~=",
                    "0.21.2"
                ]
            ]
        }
    ],
    "lcname": "clirenderer"
}
        
Elapsed time: 0.10089s