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
TerminalGV is a very simple client to display stats about your SNCF TGV/TER train in your terminal.

TerminalGV So I got bored in the train, TerminalGV is a very simple client to display stats about your SNCF TGV/TER train in your terminal. The "on-tr

Samuel 8 Dec 15, 2022
Simple Python Library to display text with color in Python Terminal

pyTextColor v1.0 Introduction pyTextColor is a simple Python Library to display colorful outputs in Terminal, etc. Note: Your Terminal or any software

Siddhesh Chavan 1 Jan 23, 2022
Module for converting 2D Python lists to fancy ASCII tables. Table2Ascii lets you display pretty tables in the terminal and on Discord.

table2ascii Module for converting 2D Python lists to a fancy ASCII/Unicode tables table2ascii ?? Installation ??‍?? Usage Convert lists to ASCII table

Jonah Lawrence 40 Jan 3, 2023
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 3, 2023
Quickly open any path on your terminal window in your $EDITOR of choice!

Tmux fpp Plugin wrapper around Facebook PathPicker. Quickly open any path on your terminal window in your $EDITOR of choice! Demo Dependencies fpp - F

null 257 Dec 28, 2022
A terminal application for managing images and artifacts in Azure Container Registry.

acr-browser acr-browser is a terminal-based user interface for managing container images and artifacts in Azure Container Registry. ?? This project ow

Sam Dobson 5 Jul 30, 2022
A dashboard for your Terminal written in the Python 3 language,

termDash is a handy little program, written in the Python 3 language, and is a small little dashboard for your terminal, designed to be a utility to help people, as well as helping new users get used to the terminal.

Rebecca White 2 Dec 3, 2021
Open a file in your locally running Visual Studio Code instance from arbitrary terminal connections.

code-connect Open a file in your locally running Visual Studio Code instance from arbitrary terminal connections. Motivation VS Code supports opening

Christian Volkmann 56 Nov 19, 2022
Darkdump - Search The Deep Web Straight From Your Terminal

Darkdump - Search The Deep Web Straight From Your Terminal About Darkdump Darkdump is a simple script written in Python3.9 in which it allows users to

Josh Schiavone 264 Dec 30, 2022
uploadgram uses your Telegram account to upload files up to 2GiB, from the Terminal.

uploadgram uploadgram uses your Telegram account to upload files up to 2GiB, from the Terminal. Heavily inspired by the telegram-upload Installing: pi

Shrimadhav U K 97 Jan 6, 2023
This a simple tool to query the awesome ippsec.rocks website from your terminal

ippsec-cli This a simple tool to query the awesome ippsec.rocks website from your terminal Installation and usage cd /opt git clone https://github.com

stark0de 5 Nov 26, 2022
💥 Share files easily over your local network from the terminal!

Fileshare ?? Share files easily over your local network from the terminal! ?? Installation # clone the repo $ git clone https://github.com/dopevog/fil

Dopevog 11 Sep 10, 2021
👻 Ghoul is an easy to use information service, allowing you to get/add information on someone or something directly from your terminal.

?? Ghoul is an easy to use information service, allowing you to get/add information on someone or something directly from your terminal. It c

Billy 11 Nov 10, 2021
Easy-to-use terminal program that can compile your code.

Description Easy-to-use terminal program that can compile your code. Installition 1. Cloning repository $ git clone https://github.com/DarkJoij/Compil

DarkJoij 1 Oct 21, 2021
WazirX Portfolio Tracker on your Terminal!

If you have been investing in crypto in India, there is a very good chance that you are using WazirX. If you are using WazirX, then you definitely know that there is no P&L report, no green arrows nor red ones. I have made a portfolio tracker where you can get all of your portfolio details right there on your Terminal/command line!

Raunit 15 Jan 10, 2022
A minimal todo list for your terminal.

todo A minimal todo list for your terminal. Installation Run the following command. pip install git+https://github.com/piero-vic/todo.git Usage todo

Piero Lescano 7 Aug 8, 2022
Stream comments, submissions from subreddits and users across reddit right in your terminal

reddit_from_terminal stream comments, submissions from subreddits and users across reddit right in your terminal Alert! : Can't watch media contents(p

Pritam Dhara 2 Dec 30, 2021
An interactive aquarium for your terminal.

sipedon An interactive aquarium for your terminal, written using pytermgui. The project got its name from the Common Watersnake, also known as Nerodia

null 17 Nov 7, 2022
GoSearch for anything from your terminal

GoSearch for anything from your terminal Requirements pip install beautifulsoup4

Malik Mouhiidine 1 Oct 2, 2021