diff --git a/1.3.md b/1.3.md
index 5a829955..c909878e 100644
--- a/1.3.md
+++ b/1.3.md
@@ -1 +1,5 @@
# Fetch 1.3
+
+- You no longer need to set the font_width value, your font size
+is now calculated by fetch.
+- Image sizing now takes terminal height into account.
diff --git a/README.md b/README.md
index d13ff6c7..80f73687 100644
--- a/README.md
+++ b/README.md
@@ -170,19 +170,6 @@ You can launch the script without a config file by using the flag `--config none
specify a custom config location using `--config path/to/config`.
-#### Sizing the image correctly
-
-**NOTE:** For the images to be sized correctly you need to set the `$font_width` variable.
-If you don't know your font width in pixels keep trying values until the image is half the
-terminal width.
-
-Once `font_width` is set the image will by default take up half the terminal width. You can
-use the launch flag `--size px` or change the config option `$image_size` to set it to a custom
-size in pixels.
-
-You can also use the launch flag `--font_width` to set it on the fly.
-
-
#### Setting the prompt height
If your shell prompt's height is greater than 1 line high, you'll need to change a config
@@ -289,7 +276,6 @@ alias fetch2="fetch \
--size px Size in pixels to make the image.
--image_backend w3m/iterm2 Which program to use to draw images.
--shuffle_dir path/to/dir Which directory to shuffle for an image.
- --font_width px Used to automatically size the image
--image_position left/right Where to display the image: (Left/Right)
--crop_mode mode Which crop mode to use
Takes the values: normal, fit, fill
diff --git a/config/config b/config/config
index d4fb2388..005cd1c3 100644
--- a/config/config
+++ b/config/config
@@ -260,11 +260,6 @@ crop_mode="normal"
# east/southwest/south/southeast
crop_offset="center"
-# Font width
-# --font_width num
-# Used when calculating dynamic image size
-font_width=5
-
# Image size
# The image is half the terminal width by default.
# --size half, px
diff --git a/fetch b/fetch
index 0048fa16..f938caaf 100755
--- a/fetch
+++ b/fetch
@@ -278,11 +278,6 @@ crop_mode="normal"
# east/southwest/south/southeast
crop_offset="center"
-# Font width
-# Used when calculating dynamic image size
-# --font_width num
-font_width=5
-
# Image size
# The image is half the terminal width by default.
# --size half, px
@@ -1865,14 +1860,34 @@ getimage () {
return
fi
- # Get lines and columns
+ # Get terminal lines and columns
columns=$(tput cols)
lines=$(tput lines)
+ # Get terminal width and height
+ printf "%b%s" '\033[14t'
+
+ index=0
+ while IFS= read -s -r -n 1 char; do
+ case "$index" in
+ "0") [ "$char" == ";" ] && index=$((index + 1)) ;;
+ "1") [ "$char" == ";" ] && index=$((index + 1)) || term_height="${term_height}${char}" ;;
+ "2") [ "$char" == "t" ] && break || term_width="${term_width}${char}"
+ esac
+ done
+
+ # Calculate font size
+ font_width=$((term_width / columns))
+ font_height=$((term_height / lines))
+
# Image size is half of the terminal
- [ "$image_size" == "half" ] && \
+ if [ "$image_size" == "half" ]; then
image_size=$((columns * font_width / 2))
+ [ "$((term_height - term_height / 4))" -lt "$image_size" ] && \
+ image_size=$((term_height - term_height / 4))
+ fi
+
# Where to draw the image
case "$image_position" in
"left")
@@ -2307,7 +2322,6 @@ usage () { cat << EOF
--size px Size in pixels to make the image.
--image_backend w3m/iterm2 Which program to use to draw images.
--shuffle_dir path/to/dir Which directory to shuffle for an image.
- --font_width px Used to automatically size the image
--image_position left/right Where to display the image: (Left/Right)
--crop_mode mode Which crop mode to use
Takes the values: normal, fit, fill
@@ -2421,7 +2435,6 @@ while [ "$1" ]; do
--size) image_size="$2" ;;
--image_backend) image_backend="$2" ;;
--shuffle_dir) shuffle_dir="$2" ;;
- --font_width) font_width="$2" ;;
--image_position) image_position="$2" ;;
--crop_mode) crop_mode="$2" ;;
--crop_offset) crop_offset="$2" ;;