posva/catimg

Feature: option to fit vertically instead of horizontally

merwok opened this issue · 5 comments

Hello and thanks for this very nice program!

It seems like big images are resized to fit the width of the console, but I would prefer to see the whole image without scrolling. Could you add a way to control this?

Alternatively, an option (or changing the default behaviour) to fit horizontally or vertically depending on the picture (i.e. use the most screen without overflowing) would also work for me.

posva commented

I remember I didn't add it because there wasn't a consistent way of getting the height of the terminal, only the width.
I don't know if the situation has changed but I'm open to contributions if it has

Do you need the height in lines or pixels?

For lines, maybe some inspiration could be taken from Python. There is a function in the standard library that checks for the COLUMNS and LINES environment variables (ref http://pubs.opengroup.org/onlinepubs/7908799/xbd/envvar.html#tag_002_003 ), or calls an ioctl: python/cpython@bcf2b59#diff-a6f29e907cbb5fffd44d453bcd7b77d5R128

I supposes that calling stty size in a sub-process would make the program too slow?

I see that the code does use an ioctl to get the columns! Could also return the lines.

I haven’t done much C but this could be a fun thing to write. I’m not available in the next weeks, so someone else feel free to take this!

Writing terminal_lines is easy but the command-line interface is harder, especially in the interaction of -w and the new flag. Could you define behaviour that you would accept?

  1. Change code from width to height, keep default to fit terminal
  2. Keep -w flag, add another flag for height (with value 0 to ask to fit height), error if both are given
  3. Something else?

(Value 0 to mean “do your best” inspired by make -j 0 meaning “use all processors”)

posva commented

I want to keep the default behaviour to fit horizontally because it makes up for more pixels and we can always scroll. 0 to make it fit vertically sounds nice to me 👍