Giter Club home page Giter Club logo

img's People

Contributors

anonymoux47 avatar dependabot[bot] avatar lainq avatar mjvbz avatar silvershade1337 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

img's Issues

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

Please use the same character used by Rich and Textual for the pixels

Can you use the same character used by Rich for the pixels?

IMG_0627

class ColorBox:
    def __rich_console__(
        self, console: Console, options: ConsoleOptions
    ) -> RenderResult:
        for y in range(0, 5):
            for x in range(options.max_width):
                h = x / options.max_width
                l = 0.1 + ((y / 5) * 0.7)
                r1, g1, b1 = colorsys.hls_to_rgb(h, l, 1.0)
                r2, g2, b2 = colorsys.hls_to_rgb(h, l + 0.7 / 10, 1.0)
                bgcolor = Color.from_rgb(r1 * 255, g1 * 255, b1 * 255)
                color = Color.from_rgb(r2 * 255, g2 * 255, b2 * 255)
                yield Segment("โ–„", Style(color=color, bgcolor=bgcolor))
            yield Segment.line()

    def __rich_measure__(
        self, console: "Console", options: ConsoleOptions
    ) -> Measurement:
        return Measurement(1, options.max_width)

Storing images in memory instead of on disk.

Discussed in #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.

Use \u2588 instead of \u2584

  • By using \u2588 instead of \u2584 removes the spaces in between the image
  • But it reduces the clarity and visibility

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.

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

Documentation

Update the old documentation with the new design.

  • Create documentation for the new module design
  • Generate a website for the documentation

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.

Gif support

Adding gif support to img. Currently, the cli is able to print the individual frames of the gif, but its not displayed in the way its supposed to be.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.