Display Images in your terminal with python

Overview

Img

Display Images in your terminal with python

Installation

The package can be installed via pip

pip install terminal-img

Quick Start

The library is really simple to get started with. Here's is an example of how you display an image

from image import DrawImage

image = DrawImage("image.png")

You can also use a url if you dont have the file locally stored

image = DrawImage.from_url("url")

Methods

image.DrawImage

  • filename: The name of the file containing the image
  • size(Optional[Tuple]) : The size of the image to be displayed. Default: 24, 24
  • draw: Whether to draw on creating an instance or wait for the user to call the function

image.DrawImage.from_url

  • url : The url of the image
  • size(Optional[Tuple]) : The size of the image to be displayed. Default: 24, 24
  • draw: Whether to draw on creating an instance or wait for the user to call the function
Comments
  • Storing images in memory instead of on disk.

    Storing images in memory instead of on disk.

    Discussed in https://github.com/pranavbaburaj/img/discussions/9

    Originally posted by AnonymouX47 October 5, 2021 This applies in three ways:

    1. A DrawImage instance holds a reference to a PIL image instead of a filepath.
      • This way, the file doesn't have to be read from disk every time the image is to be drawn.
      • This will easily allow support for cases where an image is being processed and only currently exists in memory e.g PIL image objects and more.
      • Increases the speed of repeated image drawing.
      • Of course, this also comes at the cost of memory but i think the trade-off is worth it.
      • Makes the library usable in an environment where file writes are either not possible or not wanted (maybe on some servers or cloud-based systems).
      • The other points below are hinged upon this one.
    2. Images downloaded from URLs are stored as PIL image objects instead of files.
      • This is dependent upon and shares the benefits/liabilities of (1.).
    3. Frames of GIFs are stored as PIL images instead of files.
      • This is dependent upon and shares the benefits/liabilities of (1.).
      • I think this is good because the frames are only used once, so why take them from memory to disk, then back to memory.
      • Drastically increases speed.
      • Reduces amount of disk read/write.

    Let me know what you think... I've already checked (and tested) and I'm sure 2 and 3 are possible.

    opened by pranavbaburaj 16
  • CLI

    CLI

    A CLI would be a nice addon to the project. So, user can try out printing images. The current cli need to be polished.

    CLI design.

    img <command> <filename> --param=value
    
    opened by pranavbaburaj 9
  • Discrepancies in image colour space interpretation.

    Discrepancies in image colour space interpretation.

    Here: https://github.com/pranavbaburaj/img/blob/1309c087b7b7aa5ade183c2800a0789d1529b6ab/image.py#L73 conversion to RGB is not enabled by default but here: https://github.com/pranavbaburaj/img/blob/1309c087b7b7aa5ade183c2800a0789d1529b6ab/image.py#L93 RGB values are expected.

    I actually ran into this bug while trying to print a PNG image with a single (alpha) chanel. Here: https://github.com/pranavbaburaj/img/blob/1309c087b7b7aa5ade183c2800a0789d1529b6ab/image.py#L83 pixel_values was just a tuple of integers (0s and 1s), representing the opacity of each pixel.

    So, here: https://github.com/pranavbaburaj/img/blob/1309c087b7b7aa5ade183c2800a0789d1529b6ab/image.py#L90-L92 continue was always executed on every iteration.

    Therefore, there was no output at all! As expected, the image could only be displayed when I set convert_to_rgb = True when calling draw_image().

    I think conversion to RGB should be made the default and then support for other colour spaces can be added later on.

    bug 
    opened by AnonymouX47 5
  • Disable image draw upon instantiation.

    Disable image draw upon instantiation.

    https://github.com/pranavbaburaj/img/blob/1309c087b7b7aa5ade183c2800a0789d1529b6ab/image.py#L53-L54

    I feel it's rather uncommon and unintuitive for object initialization (class instantiation) to have immediate size effects (e.g printing to the terminal in this case). For instance, PIL doesn't display an image when you create a new image object, you have to explicitly call a method to do that... among so many others.

    ObJect initialization has it's purpose... I think drawing the image will be better as a completely explicit action by calling the draw_image() method.

    This concerns both the __init__() and from_url() methods and the draw parameter in both.

    opened by AnonymouX47 4
  • Redesign

    Redesign

    • Improved image drawing.
    • Rewrote GIF display method.
    • Added from_file()
    • Added input type checks.
    • Added support for PIL image input.
    • Removed __validate_input()

    The commit messages contain much fuller details of the changes.

    opened by AnonymouX47 3
  • Convert all color spaces to RGB (fixed #7)

    Convert all color spaces to RGB (fixed #7)

    See description of #7. Closes #7

    Images in other color spaces are now converted to RGB. It's no longer optional since the ANSI color codes use RGB only.

    opened by AnonymouX47 3
  • Created requirements.txt

    Created requirements.txt

    Related Issue

    Closes: #[issue number that will be closed through this PR]

    Describe the changes you've made

    Checklist:

    • [ ] My code follows the style guidelines of this project.
    • [ ] I have performed a self-review of my own code.
    • [ ] I have commented my code, particularly in hard-to-understand areas.
    • [ ] I have made corresponding changes to the documentation.
    • [ ] My changes generate no new warnings.

    Screenshots

    | Original | Updated | | :---------------------: | :------------------------: | | original screenshot | updated screenshot |

    opened by silvershade1337 2
  • build(deps): bump pillow from 8.3.2 to 9.0.0

    build(deps): bump pillow from 8.3.2 to 9.0.0

    Bumps pillow from 8.3.2 to 9.0.0.

    Release notes

    Sourced from pillow's releases.

    9.0.0

    https://pillow.readthedocs.io/en/stable/releasenotes/9.0.0.html

    Changes

    ... (truncated)

    Changelog

    Sourced from pillow's changelog.

    9.0.0 (2022-01-02)

    • Restrict builtins for ImageMath.eval(). CVE-2022-22817 #5923 [radarhere]

    • Ensure JpegImagePlugin stops at the end of a truncated file #5921 [radarhere]

    • Fixed ImagePath.Path array handling. CVE-2022-22815, CVE-2022-22816 #5920 [radarhere]

    • Remove consecutive duplicate tiles that only differ by their offset #5919 [radarhere]

    • Improved I;16 operations on big endian #5901 [radarhere]

    • Limit quantized palette to number of colors #5879 [radarhere]

    • Fixed palette index for zeroed color in FASTOCTREE quantize #5869 [radarhere]

    • When saving RGBA to GIF, make use of first transparent palette entry #5859 [radarhere]

    • Pass SAMPLEFORMAT to libtiff #5848 [radarhere]

    • Added rounding when converting P and PA #5824 [radarhere]

    • Improved putdata() documentation and data handling #5910 [radarhere]

    • Exclude carriage return in PDF regex to help prevent ReDoS #5912 [hugovk]

    • Fixed freeing pointer in ImageDraw.Outline.transform #5909 [radarhere]

    • Added ImageShow support for xdg-open #5897 [m-shinder, radarhere]

    • Support 16-bit grayscale ImageQt conversion #5856 [cmbruns, radarhere]

    • Convert subsequent GIF frames to RGB or RGBA #5857 [radarhere]

    ... (truncated)

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • Fixed Bug

    Fixed Bug

    Fixed Bugs

    I found a small bug wjile checking the actions. Its was just a simple mistake with the variable spelling of your code.

    • [X] Fixed Variable error
    opened by mjvbz 1
  • build(deps): bump pillow from 9.0.0 to 9.0.1

    build(deps): bump pillow from 9.0.0 to 9.0.1

    Bumps pillow from 9.0.0 to 9.0.1.

    Release notes

    Sourced from pillow's releases.

    9.0.1

    https://pillow.readthedocs.io/en/stable/releasenotes/9.0.1.html

    Changes

    • In show_file, use os.remove to remove temporary images. CVE-2022-24303 #6010 [@​radarhere, @​hugovk]
    • Restrict builtins within lambdas for ImageMath.eval. CVE-2022-22817 #6009 [radarhere]
    Changelog

    Sourced from pillow's changelog.

    9.0.1 (2022-02-03)

    • In show_file, use os.remove to remove temporary images. CVE-2022-24303 #6010 [radarhere, hugovk]

    • Restrict builtins within lambdas for ImageMath.eval. CVE-2022-22817 #6009 [radarhere]

    Commits
    • 6deac9e 9.0.1 version bump
    • c04d812 Update CHANGES.rst [ci skip]
    • 4fabec3 Added release notes for 9.0.1
    • 02affaa Added delay after opening image with xdg-open
    • ca0b585 Updated formatting
    • 427221e In show_file, use os.remove to remove temporary images
    • c930be0 Restrict builtins within lambdas for ImageMath.eval
    • 75b69dd Dont need to pin for GHA
    • cd938a7 Autolink CWE numbers with sphinx-issues
    • 2e9c461 Add CVE IDs
    • See full diff in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Create pylint.yml

    Create pylint.yml

    Related Issue

    Closes: #[issue number that will be closed through this PR]

    Describe the changes you've made

    Checklist:

    • [ ] My code follows the style guidelines of this project.
    • [ ] I have performed a self-review of my own code.
    • [ ] I have commented my code, particularly in hard-to-understand areas.
    • [ ] I have made corresponding changes to the documentation.
    • [ ] My changes generate no new warnings.

    Screenshots

    | Original | Updated | | :---------------------: | :------------------------: | | original screenshot | updated screenshot |

    opened by pranavbaburaj 0
  • Prints out distorted colors on Mac terminal

    Prints out distorted colors on Mac terminal

    Describe the bug DrawImage.draw_image() seems to fail when using the default Mac terminal. It almost seems that colors are printed at random. However, the output from PyCharm terminal had no issue printing the image.

    To Reproduce Using Mac terminal. I ran the following lines of code: from image import DrawImage pfp = DrawImage.from_url(url-to-image, (32, 32)) pfp.draw_image()

    View from Mac default terminal View from default Mac terminal

    View from PyCharm terminal View from PyCharm terminal

    • Device: MacBookPro15
    • OS: macOS Catalina 10.15.7 19H1417 x86_64
    opened by surety 6
Releases(v0.0.3)
  • v0.0.3(Feb 6, 2022)

  • v0.0.2(Oct 14, 2021)

    Changelog

    • Changed the library design. DrawImage provides from_url and from_file which returns a DrawImage object. evoke the draw_image method to print the image to the console
    from image import DrawImage
    image_object = DrawImage.from_url("url")
    image_object.draw_image()
    
    • Add GIF support
    Source code(tar.gz)
    Source code(zip)
  • 0.0.1(Sep 24, 2021)

Owner
Pranav Baburaj
I am @pranavbaburaj . I am 14 and I love programming...
Pranav Baburaj
Ideas on how to quickly learn to build command-line tools

CLI-Bootcamp Ideas on how to quickly learn to build command-line tools Part 1-Bash Week1: Using Linux Lesson 1: Using Linux Shell Lab Lesson 2: How sh

Noah Gift 10 Apr 18, 2022
Python script to tabulate data formats like json, csv, html, etc

pyT PyT is a a command line tool and as well a library for visualising various data formats like: JSON HTML Table CSV XML, etc. Features Print table o

Mobolaji Abdulsalam 1 Dec 30, 2021
GetRepo-py is a command line client that queries GitHub API and searches repositories by given arguments

GetRepo-py is a command line client that queries GitHub API and searches repositories by given arguments

Davidcin 3 Feb 14, 2022
A minimalist Vim plugin manager.

A minimalist Vim plugin manager. Pros. Easy to set up: Single file. No boilerplate code required. Easy to use: Concise, intuitive syntax Super-fast pa

Junegunn Choi 30.2k Jan 08, 2023
Terminal-based keyboard testing

kbdtest kbdtest is a simple Python program that tests keyboard input using an interactive, terminal-based, visual keyboard display. It was originally

Ruunyox 12 Jul 19, 2022
Bad Apple printed out on the console with Python!

Bad Apple printed out on the console with Python!

CalvinLoke 186 Dec 01, 2022
jenkins-tui is a terminal based user interface for Jenkins.

jenkins-tui 📦 jenkins-tui is a terminal based user interface for Jenkins. 🚧 ⚠️ This app is a prototype and in very early stages of development. Ther

Craig Gumbley 22 Oct 24, 2022
MsfMania is a command line tool developed in Python that is designed to bypass antivirus software on Windows and Linux/Mac in the future

MsfMania MsfMania is a command line tool developed in Python that is designed to bypass antivirus software on Windows and Linux/Mac in the future. Sum

446 Dec 21, 2022
🌌 A Python script to generate blog banners from command line.

Auto Blog Banner Generator A Python script to generate blog banners. This script is used at RavSam. The following image is an example of the blog bann

RavSam 10 Sep 20, 2022
[WIP]An ani-cli like cli tool for movies and webseries

mov-cli A cli to browse and watch movies. Installation This project is a work in progress. However, you can try it out python git clone https://github

166 Dec 30, 2022
Custom function scheduler TUI (text-based user interface) in the console

Custom function scheduler TUI (text-based user interface) in the console

Luke 1 Oct 26, 2022
A cli tool , which shows you all the next possible words you can guess from in the game of Wordle.

wordle-helper A cli tool , which shows you all the next possible words you can guess from the Game Wordle. This repo has the code discussed in the You

1 Jan 17, 2022
A command line tool to hide and reveal information inside images (works for both PNGs and JPGs)

ImgReRite A command line tool to hide and reveal information inside images (work

Jigyasu 10 Jul 27, 2022
Python and data science snippets on the command line

Python Snippet Tool A tool to get Python and data science snippets at Data Science Simplified on the command line. You can read my article to learn ho

Khuyen Tran 19 Dec 21, 2022
Kubernetes shell: An integrated shell for working with the Kubernetes

kube-shell Kube-shell: An integrated shell for working with the Kubernetes CLI Under the hood kube-shell still calls kubectl. Kube-shell aims to provi

CloudNative Labs 2.2k Jan 08, 2023
git-partial-submodule is a command-line script for setting up and working with submodules while enabling them to use git's partial clone and sparse checkout features.

Partial Submodules for Git git-partial-submodule is a command-line script for setting up and working with submodules while enabling them to use git's

Nathan Reed 15 Sep 22, 2022
Python commandline tool for remembering linux/terminal commands

ehh Remember linux commands Commandline tool for remembering linux/terminal commands. It stores your favorite commands in ~/ehh.json in your homedir a

56 Nov 10, 2022
A command line application to analyse reports from TBC Warcraft Logs.

README A command line application to analyse reports from TBC Warcraft Logs. The application was written and tested with Python 3.9. Features Dumps an

2 Dec 17, 2021
💻 Physics2Calculator - A simple and powerful calculator for Physics 2

💻 Physics2Calculator A simple and powerful calculator for Physics 2 🔌 Predefined constants pi = 3.14159... k = 8988000000 (coulomb constant) e0 = 8.

Dylan Tintenfich 4 Dec 01, 2021
Oil is a new Unix shell. It's our upgrade path from bash to a better language and runtime

Oil is a new Unix shell. It's our upgrade path from bash to a better language and runtime. It's also for Python and JavaScript users who avoid shell!

2.4k Jan 08, 2023