Any ideas how to render images in console?

Im writing cli application and was kinda inspired of super file It can preview images in fs (example is bellow) So, i decided to implement smth similar Any libs for that?
No description
12 Replies
JavaBot
JavaBot4mo ago
This post has been reserved for your question.
Hey @Tusya <3! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Koblížkáč
Koblížkáč4mo ago
assuming you will want to use ascii character you could: - load the image into BufferedImage - read all pixels of the raster - display them into console according to their xy coordinates - for changing colors you could use ascii codes
BufferedImage i = ImageIO.read(file);
int[] rgb = i.getRaster().getPixel(x, y, new int[3]);
System.out.print("\033[38;2;" + rgb[0] + ";" + rgb[1] + ";" + rgb[2] + "m" + "█");
BufferedImage i = ImageIO.read(file);
int[] rgb = i.getRaster().getPixel(x, y, new int[3]);
System.out.print("\033[38;2;" + rgb[0] + ";" + rgb[1] + ";" + rgb[2] + "m" + "█");
obviously you are gonna want to loop through all the pixels getWidth, getHeight for that
Tusya <3
Tusya <3OP4mo ago
it will render image as it is, when pixel == char in terminal, so most of the time it wont fit in terminal there should be some resizer or smth
dan1st
dan1st4mo ago
there are ways to get the size of the terminal at least on Linux but doing something like this won't work on any system
Tusya <3
Tusya <3OP4mo ago
k, with power of chat gpt i made it work! u mean getting term size?
dan1st
dan1st4mo ago
yes, width and height of the terminal At least on Linux, there are commands for that
Tusya <3
Tusya <3OP4mo ago
afak there r platform specific stuff for that
dan1st
dan1st4mo ago
yes, exactly but that means even if it works on one device, it may not work on another
Tusya <3
Tusya <3OP4mo ago
default w and h on fallback 🙂
dan1st
dan1st4mo ago
and then you have the issue of terminals (especially on Windows) not supporting ANSI
Tusya <3
Tusya <3OP4mo ago
those gonna be unsupporter by app at the first place i guess...
JavaBot
JavaBot4mo ago
Post Closed
This post has been closed by <@997160896457625610>.
Want results from more Discord servers?
Add your server