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
Magnificent app which corrects your previous console command.

The Fuck The Fuck is a magnificent app, inspired by a @liamosaur tweet, that corrects errors in previous console commands. Is The Fuck too slow? Try t

Vladimir Iakovlev 75k Jan 02, 2023
Several tools that can be added to your `PATH` to make your life easier.

CK-CLI Tools Several tools that can be added to your PATH to make your life easier. prettypath Prints the $PATH variable in a human-readable way. It a

Christopher Kumm 2 Apr 21, 2022
Command-line script to upload videos to Youtube using theYoutube APIv3.

Introduction Command-line script to upload videos to Youtube using theYoutube APIv3. It should work on any platform (GNU/Linux, BSD, OS X, Windows, ..

Arnau Sanchez 1.9k Jan 09, 2023
⌨ Toward a more useful keyboard

Toward a more useful keyboard Steve Losh's Modern Space Cadet is an inspiration. It opened my eyes to the fact that there's a more useful keyboard hid

Jason Rudolph 1.7k Jan 01, 2023
bsp_tool provides a Command Line Interface for analysing .bsp files

bsp_tool Python library for analysing .bsp files bsp_tool provides a Command Line Interface for analysing .bsp files Current development is focused on

Jared Ketterer 64 Dec 28, 2022
Gamestonk Terminal is an awesome stock and crypto market terminal

Gamestonk Terminal is an awesome stock and crypto market terminal. A FOSS alternative to Bloomberg Terminal.

Gamestonk Terminal 18.6k Jan 03, 2023
TermPair lets developers securely share and control terminals in real time🔒

View and control terminals from your browser with end-to-end encryption 🔒

Chad Smith 1.5k Jan 05, 2023
Zero-config CLI for TypeScript package development

Despite all the recent hype, setting up a new TypeScript (x React) library can be tough. Between Rollup, Jest, tsconfig, Yarn resolutions, ESLint, and

Jared Palmer 10.5k Jan 08, 2023
A CLI minesweeper application written in 60 LoC python

This is a CLI minesweeper application written in 60 LoC python. You can use d row,column to dig and f row,column to flag/unflag

1 Dec 21, 2021
Vsm - A manager for the under-utilized mksession command in vim

Vim Session Manager A manager for the under-utilized `mksession` command in vim

Matt Williams 3 Oct 12, 2022
Ipylivebash - Run shell script in Jupyter with live output

ipylivebash ipylivebash is a library to run shell script in Jupyter with live ou

Ben Lau 6 Aug 27, 2022
Colab-xterm allows you to open a terminal in a cell

colab-xterm Colab-xterm allows you to open a terminal in a cell. Usage Install package and load the extension !pip install git+https://github.com/popc

InfuseAI 194 Dec 29, 2022
Wik is use to get information about anything on the shell using Wikipedia.

WIK wik is a tool to view wikipedia pages from your terminal. It also let you search for any wikipedia up to date article on one query from your termi

Yash Singh 340 Dec 18, 2022
Dart Version Manager CLI implemented with Python and Typer.

Dart Version Manager CLI implemented with Python and Typer.

EducUp 6 Jun 26, 2022
🗃️ Fileio-cli wrapper for fileioapi.py with fire.py, inspiration DOS

🗃️ File.io File.io simply upload a file, share the link, and after it is downloaded, the file is completely deleted. An API wrapper for the file.io w

nkot56297 2 May 12, 2022
Analyzing the most strategic words to guess on Wordle, based on letter frequency distributions

wordle-analysis Evaluating different heuristics to determine the most effective solving strategy and building an AI-powered assistant tool to help you

Sejal Dua 9 Feb 27, 2022
Voidlx is a terminal cli apps launcher made in python

Voidlx is a terminal cli apps launcher made in python

2 Nov 13, 2021
Patool is a portable command line archive file manager

Patool Patool is an archive file manager. Various archive formats can be created, extracted, tested, listed, searched, repacked and compared with pato

318 Jan 04, 2023
A selfbot made with DPY, doesn't have much commands but there's some useful commands to use.

Phantom Selfbot A selfbot made in DPY, made by Zenith. How to use Add your token in token = 'YOUR-MOMS-TOKEN-HERE' Change the prefix in prefix = If

[Ͼ⁴] Ƶephyr 2 Dec 02, 2021
This CLI give the possibility to do a queries in Star Wars API and returns a JSON in a terminal.

Star Wars CLI (swcli) This CLI give the possibility to do a queries in Star Wars API and returns a JSON in a terminal. Install $ pip install swcli Qu

Pery Lemke 5 Nov 05, 2021