lainq / img Goto Github PK
View Code? Open in Web Editor NEWA python library to display images in the terminal
Home Page: https://pranavbaburaj.github.io/img/
License: MIT License
A python library to display images in the terminal
Home Page: https://pranavbaburaj.github.io/img/
License: MIT License
The above fixes are recommended by AnonymouX47
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
Can you use the same character used by Rich for the pixels?
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)
Originally posted by AnonymouX47 October 5, 2021
This applies in three ways:
DrawImage
instance holds a reference to a PIL image instead of a filepath.
Let me know what you think... I've already checked (and tested) and I'm sure 2 and 3 are possible.
\u2588
instead of \u2584
removes the spaces in between the imageHere:
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.
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
Update the old documentation with the new design.
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.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.