From 348117efb85796a007289940b7d9e8a7d6d503c7 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 27 May 2016 14:56:09 +1000 Subject: [PATCH 1/9] Add '--size none' to use the image's original size --- neofetch | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/neofetch b/neofetch index 672cead2..7fa7817e 100755 --- a/neofetch +++ b/neofetch @@ -2202,10 +2202,8 @@ getimage () { return fi - # Get terminal lines + # Get terminal lines and columns lines=$(tput lines) - - # Get terminal columns columns=$(tput cols) # Calculate font size @@ -2229,14 +2227,24 @@ getimage () { image_size=$((percent * term_height / 100)) ;; + "none") + # Get image size so that we can do a better crop + getimgsize "$img" + crop_mode="none" + ;; + *) image_size=${image_size/px} ;; esac + # Fallback if width / height are empty. + width=${width:-$image_size} + height=${height:-$image_size} + # Where to draw the image case "$image_position" in "left") # Padding is half the terminal width + gap - padding="\033[$((image_size / font_width + gap + xoffset/font_width))C" + padding="\033[$((width / font_width + gap + xoffset/font_width))C" ;; "right") @@ -2258,9 +2266,7 @@ getimage () { # Check to see if the thumbnail exists before we do any cropping. if [ ! -f "$thumbnail_dir/$imgname" ]; then # Get image size so that we can do a better crop - size=$(identify -format "%w %h" "$img") - width=${size%% *} - height=${size##* } + getimgsize "$img" # This checks to see if height is geater than width # so we can do a better crop of portrait images. @@ -2279,7 +2285,7 @@ getimage () { -gravity south \ -background "$c" \ -extent "$size"x"$size" \ - -scale "$image_size"x"$image_size" \ + -scale "$width"x"$height" \ "$thumbnail_dir/$imgname" ;; @@ -2287,18 +2293,19 @@ getimage () { convert \ "$img" \ -trim +repage \ - -scale "$image_size"x"$image_size"^ \ - -extent "$image_size"x"$image_size" \ + -scale "$width"x"$height"^ \ + -extent "$width"x"$height" \ "$thumbnail_dir/$imgname" ;; + none) cp "$img" "$thumbnail_dir/$imgname" ;; *) convert \ "$img" \ -gravity $crop_offset \ -crop "$size"x"$size"+0+0 \ -quality 95 \ - -scale "$image_size"x"$image_size" \ + -scale "$width"x"$height" \ "$thumbnail_dir/$imgname" ;; esac @@ -2341,6 +2348,16 @@ getw3m_img_path () { # }}} +# Get Image Size {{{ + +getimgsize () { + size=$(identify -format "%w %h" "$1") + width=${size%% *} + height=${size##* } +} + +# }}} + # }}} @@ -3186,12 +3203,12 @@ fi if [ "$image" != "off" ] && [ "$image" != "ascii" ]; then case "$image_backend" in "w3m") - printf "%b%s\n" "0;1;$xoffset;$yoffset;$image_size;$image_size;;;;;$img\n4;\n3;" |\ + printf "%b%s\n" "0;1;$xoffset;$yoffset;$width;$height;;;;;$img\n4;\n3;" |\ $w3m_img_path 2>/dev/null || padding="\033[0C" ;; "iterm2") - printf "%b%s\a\n" "\033]1337;File=width=${image_size}px;height=${image_size}px;inline=1:$(base64 < "$img")" + printf "%b%s\a\n" "\033]1337;File=width=${width}px;height=${height}px;inline=1:$(base64 < "$img")" ;; esac fi From 37519f42b1bf2c0ded7a2cb27ee02de28d5f8279 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 27 May 2016 15:13:37 +1000 Subject: [PATCH 2/9] Fix issue with auto sized images --- neofetch | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/neofetch b/neofetch index 7fa7817e..58b14e0c 100755 --- a/neofetch +++ b/neofetch @@ -2229,7 +2229,9 @@ getimage () { "none") # Get image size so that we can do a better crop - getimgsize "$img" + size=$(identify -format "%w %h" "$img") + width=${size%% *} + height=${size##* } crop_mode="none" ;; @@ -2259,19 +2261,23 @@ getimage () { # Check to see if the image has a file extension, if it doesn't # then add one. case "${img##*/}" in - *"."*) imgname="$crop_mode-$crop_offset-$image_size-${img##*/}" ;; - *) imgname="$crop_mode-$crop_offset-$image_size-${img##*/}.jpg" ;; + *"."*) imgname="$crop_mode-$crop_offset-$width-$height-${img##*/}" ;; + *) imgname="$crop_mode-$crop_offset-$width-$height-${img##*/}.jpg" ;; esac # Check to see if the thumbnail exists before we do any cropping. if [ ! -f "$thumbnail_dir/$imgname" ]; then # Get image size so that we can do a better crop - getimgsize "$img" + if [ -z "$size" ]; then + size=$(identify -format "%w %h" "$img") + og_width=${size%% *} + og_height=${size##* } + fi # This checks to see if height is geater than width # so we can do a better crop of portrait images. - size=$height - [ "$height" -gt "$width" ] && size=$width + size=$og_height + [ "$og_height" -gt "$og_width" ] && size=$og_width case "$crop_mode" in fit) @@ -2348,16 +2354,6 @@ getw3m_img_path () { # }}} -# Get Image Size {{{ - -getimgsize () { - size=$(identify -format "%w %h" "$1") - width=${size%% *} - height=${size##* } -} - -# }}} - # }}} From bd070d5059ce524df51c23b77aca7acfe825e4ef Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 27 May 2016 15:23:02 +1000 Subject: [PATCH 3/9] Update docs --- README.md | 3 ++- config/config | 2 +- neofetch | 5 +++-- neofetch.1 | 4 +++- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e100346a..a9887879 100644 --- a/README.md +++ b/README.md @@ -413,7 +413,8 @@ alias fetch2="fetch \ --image type Image source. Where and what image we display. Possible values: wall, ascii, /path/to/img, /path/to/dir/, off - --size 20px | --size 20% Size to make the image, takes pixels or a percentage. + --size 00px | --size 00% How to size the image. + Possible values: auto, 00px, 00%, none --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 5f77e057..4ad11cfa 100644 --- a/config/config +++ b/config/config @@ -317,7 +317,7 @@ crop_offset="center" # Image size # The image is half the terminal width by default. -# --size auto, 00px, 00% +# --size auto, 00px, 00%, none image_size="auto" # Right gap between image and text diff --git a/neofetch b/neofetch index 58b14e0c..bf972fbc 100755 --- a/neofetch +++ b/neofetch @@ -344,7 +344,7 @@ crop_offset="center" # Image size # The image is half the terminal width by default. -# --size auto, 00px, 00% +# --size auto, 00px, 00%, none image_size="auto" # Right gap between image and text @@ -2905,7 +2905,8 @@ usage () { cat << EOF --image type Image source. Where and what image we display. Possible values: wall, ascii, /path/to/img, /path/to/dir/, off - --size 20px | --size 20% Size to make the image, takes pixels or a percentage. + --size 00px | --size 00% How to size the image. + Possible values: auto, 00px, 00%, none --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/neofetch.1 b/neofetch.1 index 0e633fd7..8526a7e1 100644 --- a/neofetch.1 +++ b/neofetch.1 @@ -172,7 +172,9 @@ Image source. Where and what image we display. Possible values: wall, ascii, /path/to/img, /path/to/dir/, off .TP .B \--size 'size' -Size to make the image, takes pixels or a percentage. +How to size the image. +.br +Possible values: auto, 00px, 00%, none .TP .B \--image_position 'left/right' Where to display the image: (Left/Right) From a98d96eb8c47fd5bd0fbaee4fb04978a658ca84d Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 28 May 2016 14:01:44 +1000 Subject: [PATCH 4/9] Halve font width on iTerm2 --- neofetch | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/neofetch b/neofetch index bf972fbc..c73e52a7 100755 --- a/neofetch +++ b/neofetch @@ -2207,7 +2207,12 @@ getimage () { columns=$(tput cols) # Calculate font size - font_width=$((term_width / columns)) + if [ "$os" == "Mac OS X" ]; then + font_width=$((term_width / columns)) + else + # Fixes padding issues in iTerm2. + font_width=$((term_width / columns / 2)) + fi # Image size is half of the terminal case "$image_size" in From 7023a37658143b13d0665701df46554e6f64ba3f Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 28 May 2016 14:02:32 +1000 Subject: [PATCH 5/9] Fixed wrong order --- neofetch | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/neofetch b/neofetch index c73e52a7..d9b3dfc0 100755 --- a/neofetch +++ b/neofetch @@ -2208,10 +2208,10 @@ getimage () { # Calculate font size if [ "$os" == "Mac OS X" ]; then - font_width=$((term_width / columns)) + font_width=$((term_width / columns / 2)) else # Fixes padding issues in iTerm2. - font_width=$((term_width / columns / 2)) + font_width=$((term_width / columns)) fi # Image size is half of the terminal From 77fe15cb29adcb49a529c37066633a6d8808d7f3 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 28 May 2016 14:04:52 +1000 Subject: [PATCH 6/9] Move comment to right place --- neofetch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neofetch b/neofetch index d9b3dfc0..36121e47 100755 --- a/neofetch +++ b/neofetch @@ -2208,9 +2208,9 @@ getimage () { # Calculate font size if [ "$os" == "Mac OS X" ]; then + # Fixes padding issues in iTerm2. font_width=$((term_width / columns / 2)) else - # Fixes padding issues in iTerm2. font_width=$((term_width / columns)) fi From 70aa01aebbfe7617eddecc5f45a302bd42747f1d Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 28 May 2016 14:07:19 +1000 Subject: [PATCH 7/9] Move comparison to inside if statement --- neofetch | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/neofetch b/neofetch index 36121e47..317fded6 100755 --- a/neofetch +++ b/neofetch @@ -2277,12 +2277,12 @@ getimage () { size=$(identify -format "%w %h" "$img") og_width=${size%% *} og_height=${size##* } - fi - # This checks to see if height is geater than width - # so we can do a better crop of portrait images. - size=$og_height - [ "$og_height" -gt "$og_width" ] && size=$og_width + # This checks to see if height is geater than width + # so we can do a better crop of portrait images. + size=$og_height + [ "$og_height" -gt "$og_width" ] && size=$og_width + fi case "$crop_mode" in fit) From 3636abd2aca80c48e611baaebb476dc58271f0be Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Tue, 31 May 2016 12:01:26 +1000 Subject: [PATCH 8/9] Disable OS X font width changes --- neofetch | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/neofetch b/neofetch index 317fded6..60166376 100755 --- a/neofetch +++ b/neofetch @@ -2207,12 +2207,12 @@ getimage () { columns=$(tput cols) # Calculate font size - if [ "$os" == "Mac OS X" ]; then - # Fixes padding issues in iTerm2. - font_width=$((term_width / columns / 2)) - else - font_width=$((term_width / columns)) - fi + # if [ "$os" == "Mac OS X" ]; then + # # Fixes padding issues in iTerm2. + # font_width=$((term_width / columns / 2)) + # else + font_width=$((term_width / columns)) + # fi # Image size is half of the terminal case "$image_size" in From c3164b7cfee974cd74c182fc554620f15c937ba5 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Tue, 31 May 2016 12:09:21 +1000 Subject: [PATCH 9/9] Remove comments --- neofetch | 5 ----- 1 file changed, 5 deletions(-) diff --git a/neofetch b/neofetch index 60166376..bef10daf 100755 --- a/neofetch +++ b/neofetch @@ -2207,12 +2207,7 @@ getimage () { columns=$(tput cols) # Calculate font size - # if [ "$os" == "Mac OS X" ]; then - # # Fixes padding issues in iTerm2. - # font_width=$((term_width / columns / 2)) - # else font_width=$((term_width / columns)) - # fi # Image size is half of the terminal case "$image_size" in