aboutsummaryrefslogtreecommitdiffstats
path: root/thumbnailer.go
diff options
context:
space:
mode:
Diffstat (limited to 'thumbnailer.go')
-rw-r--r--thumbnailer.go10
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)