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
Container images for portable development environments

Docker Dev Spin up a container to develop from anywhere! To run, just: docker run -ti aghost7/nodejs-dev:boron tmux new Alternatively, if on Linux: p

Jonathan Boudreau 163 Dec 22, 2022
Salesforce object access auditor

Salesforce object access auditor Released as open source by NCC Group Plc - https://www.nccgroup.com/ Developed by Jerome Smith @exploresecurity (with

NCC Group Plc 90 Sep 19, 2022
Create animated ASCII-art for the command line almost instantly!

clippy Create and play colored 🟥 🟩 🟦 or colorless ⬛️ ⬜️ animated, or static, ASCII-art in the command line! clippy can help if you are wanting to;

Connor 10 Jun 26, 2022
Create argparse subcommands with decorators.

python-argparse-subdec This is a very simple Python package that allows one to create argparse's subcommands via function decorators. Usage Create a S

Gustavo José de Sousa 7 Oct 21, 2022
A simple command line virtual operating system, written in python

Virtual operating system A simple virtual operating system written in python. (Under development). Currently, the following commands are supported: Co

B.Jothin kumar 7 Nov 15, 2022
Themes for the kitty terminal emulator

Themes for the kitty terminal This is a collection of themes for the kitty terminal emulator. The themes were initially imported from dexpota/kitty-th

Kovid Goyal 190 Jan 05, 2023
Bonjour Software pypahe is a Python Package Helper command-line tool.

pypahe Bonjour Software pypahe is a Python Package Helper command-line tool. Requirements Docker runtime Usage print the latest available version of a

Bonjour Software 0 Aug 10, 2021
🌌 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
Booky - A command line utility for bookmarking files on your terminal!

Booky A command line utility for bookmarking files for quick access With it you can: Bookmark and delete your (aliases of) files at demand Launch them

Pran 1 Sep 11, 2022
Fylm is a wonderful automated command line app for organizing your film media.

Overview Fylm is a wonderful automated command line app for organizing your film media. You can pronounce it Film or File 'em, whichever you like! It

Brandon Shelley 30 Dec 05, 2022
CLI tool for typescript tasks & migrations

typed CLI tool for typescript tasks & migrations Installation Usage $ typed --list Subcommands: bootstrap 🔨 Bootstrap your environment for TypeS

Lob 1 Nov 15, 2021
Command line tool for monitoring changes of File entities scoped in a Synapse File View

Synapse Monitoring Provides tools for monitoring and keeping track of File entity changes in Synapse with the use of File Views. Learn more about File

Sage Bionetworks 3 May 28, 2022
Customisable pharmacokinetic model accessible via bash CLI allowing for variable dose calculations as well as intravenous and subcutaneous administration calculations

Pharmacokinetic Modelling Group Project A PharmacoKinetic (PK) modelling function for analysis of injected solute dynamics over time, developed by Gro

1 Oct 24, 2021
The project help you to quickly build layouts in terminal,cross-platform

The project help you to quickly build layouts in terminal,cross-platform

gojuukaze 133 Nov 30, 2022
Present - A terminal-based presentation tool with colors and effects.

present A terminal-based presentation tool with colors and effects. You can also play a codio (pre-recorded code block) on a slide. present is built o

Vinayak Mehta 4.2k Jan 03, 2023
CmdTube is a Python CLI library for searching, downloading, and watching YouTube tutorials

CmdTube is a Python CLI library for searching, downloading, and watching YouTube tutorials. This library was made with programmers in mind and it's dedicated to every programmer who watches YouTube v

Samuel Ayomide Ogunleke 2 Aug 22, 2022
Access hacksec.in from your command-line

Access hacksec.in from your command-line

hacksec.in 3 Oct 26, 2022
Program Command Line Interface (CLI) Sederhana: Pemesanan Nasi Goreng Hekel

Program ini merupakan aplikasi yang berjalan di dalam command line (terminal). Program ini menggunakan built-in library python yaitu argparse yang dapat menerima parameter saat program ini dijalankan

Habib Abdurrasyid 5 Nov 19, 2021
Openstack bucket retention cli

Openstack bucket retention cli

Fatih Sarhan 3 Apr 03, 2022
The easiest way to create beautiful CLI for your programs.

The Yandere is a program written in Python3, allowing you to create your own beautiful CLI tool.

Billy 31 Dec 20, 2022