diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2026-05-27 21:42:22 -0700 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2026-05-27 21:42:22 -0700 |
| commit | a15f662bac79b1e0c44a0b8cbd2b06139e4916ba (patch) | |
| tree | 6e068bc48253db1a75f3b2ece4e7a2b6a302ad66 /thumbnailer.go | |
| parent | e6c6aa9c35de49cc0a66f010a8de7aface7d648e (diff) | |
| download | imgutil-a15f662bac79b1e0c44a0b8cbd2b06139e4916ba.tar.zst | |
Handle some weird sizes
Diffstat (limited to 'thumbnailer.go')
| -rw-r--r-- | thumbnailer.go | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/thumbnailer.go b/thumbnailer.go index bba447c..3e1be07 100644 --- a/thumbnailer.go +++ b/thumbnailer.go @@ -26,7 +26,7 @@ import ( var ( x = flag.Int("x", 15, "set image width in columns") - y = flag.Int("y", 10, "set image height in rows") + y = flag.Int("y", 0, "set image height in rows") ) func isDir(filename string) (bool, error) { @@ -81,11 +81,14 @@ func load(filename string) (image.Image, error) { func printImg(img image.Image, cols, lines int) (string, int) { // Try not to stretch the image. - if lines == 0 || cols != 0 && img.Bounds().Dy()*cols <= img.Bounds().Dx()*lines*5/2 { + if lines <= 0 || img.Bounds().Dy()*cols <= img.Bounds().Dx()*lines*5/2 { lines = img.Bounds().Dy() * cols / (img.Bounds().Dx() * 5 / 2) } else { cols = img.Bounds().Dx() * lines * 5 / 2 / img.Bounds().Dy() } + if lines == 0 || cols == 0 { + return "", 0 + } dst := image.NewRGBA(image.Rect(0, 0, cols, 2*lines)) draw.BiLinear.Scale(dst, dst.Bounds(), img, img.Bounds(), draw.Over, nil) @@ -178,6 +181,9 @@ func readDir(d string) ([]string, error) { func thumbnailer(args []string) error { cols := *x lines := *y + if cols <= 0 { + return fmt.Errorf("-x must be greater than 0") + } termCols, _, err := term.GetSize(1) if err != nil { return fmt.Errorf("terminal size: %s", err) |
