Compare commits

...

4 commits
master ... img2

Author SHA1 Message Date
dylan araps
bd0f396305 general: cleanup 2017-12-14 10:32:18 +11:00
dylan araps
3c03c47f50 config: Update comment 2017-12-14 10:25:47 +11:00
dylan araps
b628ec0f4d image: Simplify crop 2017-12-14 10:22:23 +11:00
dylan araps
6c238a03b2 image: Simplify image handling. 2017-12-14 10:06:16 +11:00
3 changed files with 38 additions and 117 deletions

View file

@ -617,18 +617,8 @@ image_loop="off"
# Values: 'dir' # Values: 'dir'
thumbnail_dir="${XDG_CACHE_HOME:-${HOME}/.cache}/thumbnails/neofetch" thumbnail_dir="${XDG_CACHE_HOME:-${HOME}/.cache}/thumbnails/neofetch"
# Crop mode
#
# Default: 'normal'
# Values: 'normal', 'fit', 'fill'
# Flag: --crop_mode
#
# See this wiki page to learn about the fit and fill options.
# https://github.com/dylanaraps/neofetch/wiki/What-is-Waifu-Crop%3F
crop_mode="normal"
# Crop offset # Crop offset
# Note: Only affects 'normal' crop mode. # Note: Only affects 'square' image size.
# #
# Default: 'center' # Default: 'center'
# Values: 'northwest', 'north', 'northeast', 'west', 'center' # Values: 'northwest', 'north', 'northeast', 'west', 'center'
@ -637,20 +627,21 @@ crop_mode="normal"
crop_offset="center" crop_offset="center"
# Image size # Image size
# The image is half the terminal width by default. # NOTE: 'square' is the OLD behavior.
# NOTE: 'auto' keeps image aspect ratio and size where possible.
# #
# Default: 'auto' # Default: 'auto'
# Values: 'auto', '00px', '00%', 'none' # Values: 'auto', 'square'
# Flags: --image_size # Flags: --image_size
# --size # --size
image_size="auto" image_size="auto"
# Ggap between image and text # Gap between image and text
# #
# Default: '3' # Default: '4'
# Values: 'num', '-num' # Values: 'num', '-num'
# Flag: --gap # Flag: --gap
gap=3 gap=4
# Image offsets # Image offsets
# Only works with the w3m backend. # Only works with the w3m backend.

119
neofetch
View file

@ -2667,50 +2667,32 @@ get_image_size() {
font_width="$((term_width / columns))" font_width="$((term_width / columns))"
font_height="$((term_height / lines))" font_height="$((term_height / lines))"
# Get image size.
size="$(identify -format "%w %h" "$image")"
width="${size%% *}"
height="${size##* }"
case "$image_size" in case "$image_size" in
"auto") "square")
image_size="$((columns * font_width / 2))" width="$((columns * font_width / 2))"
term_height="$((term_height - term_height / 4))" height="$width"
((term_height < image_size)) && \
image_size="$term_height"
;; ;;
*"%") *)
percent="${image_size/\%}" while (( width >= (term_width / 2) ||
image_size="$((percent * term_width / 100))" height >= (term_height / 2) )); do
width="$((width * 10 / 15))"
(((percent * term_height / 50) < image_size)) && \ height="$((height * 10 / 15))"
image_size="$((percent * term_height / 100))"
;;
"none")
# Get image size so that we can do a better crop.
size="$(identify -format "%w %h" "$image")"
width="${size%% *}"
height="${size##* }"
crop_mode="none"
while (( "$width" >= ("$term_width" / 2) ||
"$height" >= "$term_height" )); do
width="$((width / 2))"
height="$((height / 2))"
done done
;; ;;
*) image_size="${image_size/px}" ;;
esac esac
width="${width:-$image_size}"
height="${height:-$image_size}"
text_padding="$((width / font_width + gap + xoffset/font_width))" text_padding="$((width / font_width + gap + xoffset/font_width))"
} }
make_thumbnail() { make_thumbnail() {
# Name the thumbnail using variables so we can # Name the thumbnail using variables so we can use it later.
# use it later. image_name="$image_size-$crop_offset-$width-$height-${image##*/}"
image_name="$crop_mode-$crop_offset-$width-$height-${image##*/}"
# Handle file extensions. # Handle file extensions.
case "${image##*.}" in case "${image##*.}" in
@ -2722,62 +2704,17 @@ make_thumbnail() {
# Create the thumbnail dir if it doesn't exist. # Create the thumbnail dir if it doesn't exist.
mkdir -p "$thumbnail_dir" mkdir -p "$thumbnail_dir"
# Check to see if the thumbnail exists before we do any cropping. [[ ! -f "$thumbnail_dir/$image_name" ]] && \
if [[ ! -f "$thumbnail_dir/$image_name" ]]; then convert \
# Get image size so that we can do a better crop. "$image" \
if [[ -z "$size" ]]; then -strip \
size="$(identify -format "%w %h" "$image")" -quality 50 \
og_width="${size%% *}" -gravity "$crop_offset" \
og_height="${size##* }" -background none \
-sample "$width"x"$height"^ \
-extent "$width"x"$height" \
"$thumbnail_dir/$image_name"
# This checks to see if height is greater than width
# so we can do a better crop of portrait images.
size="$og_height"
((og_height > og_width)) && size="$og_width"
fi
case "$crop_mode" in
"fit")
c="$(convert "$image" \
-colorspace srgb \
-format "%[pixel:p{0,0}]" info:)"
convert \
-background none \
"$image" \
-trim +repage \
-gravity south \
-background "$c" \
-extent "$size"x"$size" \
-scale "$width"x"$height" \
"$thumbnail_dir/$image_name"
;;
"fill")
convert \
-background none \
"$image" \
-trim +repage \
-scale "$width"x"$height"^ \
-extent "$width"x"$height" \
"$thumbnail_dir/$image_name"
;;
"none") cp "$image" "$thumbnail_dir/$image_name" ;;
*)
convert \
-background none \
"$image" \
-gravity "$crop_offset" \
-crop "$size"x"$size"+0+0 \
-quality 95 \
-scale "$width"x"$height" \
"$thumbnail_dir/$image_name"
;;
esac
fi
# The final image.
image="$thumbnail_dir/$image_name" image="$thumbnail_dir/$image_name"
} }
@ -4465,11 +4402,9 @@ ASCII:
IMAGE: IMAGE:
--loop Redraw the image constantly until Ctrl+C is used. This fixes issues --loop Redraw the image constantly until Ctrl+C is used. This fixes issues
in some terminals emulators when using image mode. in some terminals emulators when using image mode.
--size 00px | --size 00% How to size the image. --size auto | --size square How to size the image.
Possible values: auto, 00px, 00%, none Possible values: auto, 00px, 00%, none
--crop_mode mode Which crop mode to use --crop_offset value Change the crop offset for square mode.
Takes the values: normal, fit, fill
--crop_offset value Change the crop offset for normal mode.
Possible values: northwest, north, northeast, Possible values: northwest, north, northeast,
west, center, east, southwest, south, southeast west, center, east, southwest, south, southeast

View file

@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.4. .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.5.
.TH NEOFETCH "1" "September 2017" "Neofetch 3.3.0" "User Commands" .TH NEOFETCH "1" "December 2017" "Neofetch 3.3.1-git" "User Commands"
.SH NAME .SH NAME
Neofetch \- A fast, highly customizable system info script Neofetch \- A fast, highly customizable system info script
.SH SYNOPSIS .SH SYNOPSIS
@ -259,16 +259,11 @@ Possible values: bar, infobar, barinfo, off
Redraw the image constantly until Ctrl+C is used. This fixes issues Redraw the image constantly until Ctrl+C is used. This fixes issues
in some terminals emulators when using image mode. in some terminals emulators when using image mode.
.TP .TP
\fB\-\-size\fR 00px | \fB\-\-size\fR 00% \fB\-\-size\fR auto | \fB\-\-size\fR square How to size the image.
How to size the image.
Possible values: auto, 00px, 00%, none Possible values: auto, 00px, 00%, none
.TP .TP
\fB\-\-crop_mode\fR mode
Which crop mode to use
Takes the values: normal, fit, fill
.TP
\fB\-\-crop_offset\fR value \fB\-\-crop_offset\fR value
Change the crop offset for normal mode. Change the crop offset for square mode.
Possible values: northwest, north, northeast, Possible values: northwest, north, northeast,
west, center, east, southwest, south, southeast west, center, east, southwest, south, southeast
.TP .TP