nabijaczleweli / termimage

Display images in your terminal, kind of
MIT License
209 stars 4 forks source link

Use unicode block #4

Closed joshtriplett closed 8 years ago

joshtriplett commented 8 years ago

You can double the vertical resolution by printing a Unicode "upper block" character, using the foreground for the upper pixel and the background for the lower pixel. (This also requires an adjustment to the aspect ratio calculation.)

nabijaczleweli commented 8 years ago

Aspect ratio is (not) preserved by image, so I have little control over that, but the idea seems nice

joshtriplett commented 8 years ago

You can read out the size, and calculate the new size yourself, rather than using the aspect-ratio-preserving resize.

Terminal characters have a rectangular shape, with more height than width; when not using Unicode, you'd want to take that into account, and resize the image to have twice as much width as height compared to its natural aspect ratio. For instance, you could take a 1600x1200 image and resize it to 80x30 rather than 80x60, which would make the image printed in the terminal look closer to correct.

However, when using a unicode half-block character, you'd want to resize the image preserving aspect ratio (1600x1200 -> 80x60) and then use two pixel rows per text row.

nabijaczleweli commented 8 years ago

Yeah, you're right.

nabijaczleweli commented 8 years ago

Terminal characters have a rectangular shape

Which is inconsistent across any and all implementations :P

joshtriplett commented 8 years ago

@nabijaczleweli True, but it'll generally be closer to 2:1 than 1:1; terminal fonts are almost never square. So, 2:1 should generally produce better results.

nabijaczleweli commented 8 years ago

I'm bad at numbers, misclosed :v

nabijaczleweli commented 8 years ago

DOPE SHIT, BOIZ

nabijaczleweli commented 8 years ago

@joshtriplett Can you verify with -a truecolor?

joshtriplett commented 8 years ago

Yeah, that works, and produces a much better aspect ratio as well.

The unicode block thing came readily to mind because I'd done a similar experiment as a test of the ansi_term module after adding truecolor support to it. My quick-and-dirty version didn't have any of the error handling or command-line handling that yours does, though.

Screenshots of the truecolor Unicode-block version:

rust-logo tali

Also, I'd suggest subtracting one from the target height, so that the subsequent prompt doesn't scroll the top of the image off the screen.

nabijaczleweli commented 8 years ago

That's unavoidable on Windooze, but I might be able to do something about it on Linux, open a separate issue, please?

nabijaczleweli commented 8 years ago

@joshtriplett Can you please make an SS of this image: DS3 SS? That way we'd have a consistent comparison base for multiple platforms