Skip to content

Commit

Permalink
Make it possible to partially specify the geometry.
Browse files Browse the repository at this point in the history
Issues #66 #64
  • Loading branch information
hzeller committed Nov 30, 2021
1 parent 7185c49 commit daa6f31
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ grid uses `--grid=2` and is pixelated with `-pq`).
```
usage: timg [options] <image/video> [<image/video>...]
Options:
-g<w>x<h> : Output geometry in character cells. Terminal is 160x50
-g<w>x<h> : Output geometry in character cells. Partial geometry
leaving out one value -g<w>x or -gx<h> is possible,
the other value it then derived from the terminal size.
Default derived from terminal size is 160x50
-p<pixelation> : Pixelation: 'h' = half blocks 'q' = quarter blocks
'k' = kitty graphics 'i' = iTerm2 graphics
Default: Auto-detect graphics, otherwise 'quarter'.
Expand Down
8 changes: 7 additions & 1 deletion man/timg.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.\" Automatically generated by Pandoc 2.9.2.1
.\" Automatically generated by Pandoc 2.13
.\"
.TH "timg" "1" "Feb 2021" "" ""
.hy
Expand Down Expand Up @@ -52,6 +52,12 @@ By default, the size is determined by the available space in the
terminal.
The image is scaled to fit inside the available box to fill the screen;
see \f[B]-W\f[R] if you want to fill the width.
.RS
.PP
It is possible to only partially specify the size before or after the
\f[B]x\f[R] separator, like \f[B]-gx\f[R] or \f[B]-gx\f[R].
The corresponding other value is then derived from the terminal size.
.RE
.TP
\f[B]-p\f[R] \f[I]<[h|q|k|i]>\f[R], \f[B]--pixelation\f[R]=\f[I][h|q|k|i]\f[R]
Choice for pixelation of the content.
Expand Down
6 changes: 5 additions & 1 deletion man/timg.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@ these file decoders (GraphicsMagick or libav respectively).

## General Options
**-g** *&lt;width&gt;x&lt;height&gt;*
: Output image to fit inside given geometry. By default, the size is
: Output image to fit inside given geometry. By default, the size is
determined by the available space in the terminal. The image is
scaled to fit inside the available box to fill the screen; see **-W** if
you want to fill the width.

It is possible to only partially specify the size before or after the
**x** separator, like **-g<width>x** or **-gx<height>**. The corresponding
other value is then derived from the terminal size.

**-p** *&lt;[h|q|k|i]&gt;*, **-\-pixelation**=*[h|q|k|i]*
: Choice for pixelation of the content. Value 'h' chooses unicode half
block characters, while 'q' chooses quarter blocks.
Expand Down
13 changes: 10 additions & 3 deletions src/timg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ static int usage(const char *progname, ExitCode exit_code,
fprintf(stderr, "usage: %s [options] <%s> [<%s>...]\n", progname,
kFileType, kFileType);
fprintf(stderr, "\e[1mOptions\e[0m:\n"
"\t-g<w>x<h> : Output geometry in character cells. Terminal is %dx%d\n"
"\t-g<w>x<h> : Output geometry in character cells. Partial geometry\n"
"\t leaving out one value -g<w>x or -gx<h> is possible,\n"
"\t the other value it then derived from the terminal size.\n"
"\t Default derived from terminal size is %dx%d\n"
"\t-p<pixelation> : Pixelation: 'h' = half blocks 'q' = quarter blocks\n"
"\t 'k' = kitty graphics 'i' = iTerm2 graphics\n"
"\t Default: Auto-detect graphics, otherwise 'quarter'.\n"
Expand Down Expand Up @@ -393,8 +396,10 @@ int main(int argc, char *argv[]) {
long_options, &option_index))!=-1) {
switch (opt) {
case 'g':
if (sscanf(optarg, "%dx%d",
&geometry_width, &geometry_height) < 2) {
// Parse xHEIGHT, WIDTHx, WIDTHxHEIGHT
if ((sscanf(optarg, "x%d", &geometry_height) == 0) &&
(sscanf(optarg, "%dx%d",
&geometry_width, &geometry_height) < 1)) {
fprintf(stderr, "Invalid size spec '%s'", optarg);
return usage(argv[0], ExitCode::kParameterError,
geometry_width, geometry_height);
Expand Down Expand Up @@ -812,6 +817,8 @@ int main(int argc, char *argv[]) {
if (verbose) {
fprintf(stderr, "Terminal cells: %dx%d cell-pixels: %dx%d\n",
term.cols, term.rows, term.font_width_px, term.font_height_px);
fprintf(stderr, "Active Geometry: %dx%d\n",
geometry_width, geometry_height);
const Duration d = end_show - start_show;
const uint64_t written_bytes =
sequencer.bytes_total() - sequencer.bytes_skipped();
Expand Down

0 comments on commit daa6f31

Please sign in to comment.