Merge pull request #266 from dylanaraps/size_none

Add '--size none' to disable cropping / resizing the images.
This commit is contained in:
Dylan Araps 2016-05-31 12:12:44 +10:00
commit af8646fe66
4 changed files with 41 additions and 24 deletions

View file

@ -423,7 +423,8 @@ alias fetch2="fetch \
--image type Image source. Where and what image we display. --image type Image source. Where and what image we display.
Possible values: wall, ascii, Possible values: wall, ascii,
/path/to/img, /path/to/dir/, off /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) --image_position left/right Where to display the image: (Left/Right)
--crop_mode mode Which crop mode to use --crop_mode mode Which crop mode to use
Takes the values: normal, fit, fill Takes the values: normal, fit, fill

View file

@ -324,7 +324,7 @@ crop_offset="center"
# Image size # Image size
# The image is half the terminal width by default. # The image is half the terminal width by default.
# --size auto, 00px, 00% # --size auto, 00px, 00%, none
image_size="auto" image_size="auto"
# Right gap between image and text # Right gap between image and text

View file

@ -351,7 +351,7 @@ crop_offset="center"
# Image size # Image size
# The image is half the terminal width by default. # The image is half the terminal width by default.
# --size auto, 00px, 00% # --size auto, 00px, 00%, none
image_size="auto" image_size="auto"
# Right gap between image and text # Right gap between image and text
@ -2221,10 +2221,8 @@ getimage () {
return return
fi fi
# Get terminal lines # Get terminal lines and columns
lines=$(tput lines) lines=$(tput lines)
# Get terminal columns
columns=$(tput cols) columns=$(tput cols)
# Calculate font size # Calculate font size
@ -2248,14 +2246,26 @@ getimage () {
image_size=$((percent * term_height / 100)) image_size=$((percent * term_height / 100))
;; ;;
"none")
# Get image size so that we can do a better crop
size=$(identify -format "%w %h" "$img")
width=${size%% *}
height=${size##* }
crop_mode="none"
;;
*) image_size=${image_size/px} ;; *) image_size=${image_size/px} ;;
esac esac
# Fallback if width / height are empty.
width=${width:-$image_size}
height=${height:-$image_size}
# Where to draw the image # Where to draw the image
case "$image_position" in case "$image_position" in
"left") "left")
# Padding is half the terminal width + gap # 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") "right")
@ -2270,21 +2280,23 @@ getimage () {
# Check to see if the image has a file extension, if it doesn't # Check to see if the image has a file extension, if it doesn't
# then add one. # then add one.
case "${img##*/}" in case "${img##*/}" in
*"."*) imgname="$crop_mode-$crop_offset-$image_size-${img##*/}" ;; *"."*) imgname="$crop_mode-$crop_offset-$width-$height-${img##*/}" ;;
*) imgname="$crop_mode-$crop_offset-$image_size-${img##*/}.jpg" ;; *) imgname="$crop_mode-$crop_offset-$width-$height-${img##*/}.jpg" ;;
esac esac
# Check to see if the thumbnail exists before we do any cropping. # Check to see if the thumbnail exists before we do any cropping.
if [ ! -f "$thumbnail_dir/$imgname" ]; then if [ ! -f "$thumbnail_dir/$imgname" ]; then
# Get image size so that we can do a better crop # Get image size so that we can do a better crop
size=$(identify -format "%w %h" "$img") if [ -z "$size" ]; then
width=${size%% *} size=$(identify -format "%w %h" "$img")
height=${size##* } og_width=${size%% *}
og_height=${size##* }
# This checks to see if height is geater than width # This checks to see if height is geater than width
# so we can do a better crop of portrait images. # so we can do a better crop of portrait images.
size=$height size=$og_height
[ "$height" -gt "$width" ] && size=$width [ "$og_height" -gt "$og_width" ] && size=$og_width
fi
case "$crop_mode" in case "$crop_mode" in
fit) fit)
@ -2298,7 +2310,7 @@ getimage () {
-gravity south \ -gravity south \
-background "$c" \ -background "$c" \
-extent "$size"x"$size" \ -extent "$size"x"$size" \
-scale "$image_size"x"$image_size" \ -scale "$width"x"$height" \
"$thumbnail_dir/$imgname" "$thumbnail_dir/$imgname"
;; ;;
@ -2306,18 +2318,19 @@ getimage () {
convert \ convert \
"$img" \ "$img" \
-trim +repage \ -trim +repage \
-scale "$image_size"x"$image_size"^ \ -scale "$width"x"$height"^ \
-extent "$image_size"x"$image_size" \ -extent "$width"x"$height" \
"$thumbnail_dir/$imgname" "$thumbnail_dir/$imgname"
;; ;;
none) cp "$img" "$thumbnail_dir/$imgname" ;;
*) *)
convert \ convert \
"$img" \ "$img" \
-gravity $crop_offset \ -gravity $crop_offset \
-crop "$size"x"$size"+0+0 \ -crop "$size"x"$size"+0+0 \
-quality 95 \ -quality 95 \
-scale "$image_size"x"$image_size" \ -scale "$width"x"$height" \
"$thumbnail_dir/$imgname" "$thumbnail_dir/$imgname"
;; ;;
esac esac
@ -2912,7 +2925,8 @@ usage () { cat << EOF
--image type Image source. Where and what image we display. --image type Image source. Where and what image we display.
Possible values: wall, ascii, Possible values: wall, ascii,
/path/to/img, /path/to/dir/, off /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) --image_position left/right Where to display the image: (Left/Right)
--crop_mode mode Which crop mode to use --crop_mode mode Which crop mode to use
Takes the values: normal, fit, fill Takes the values: normal, fit, fill
@ -3209,12 +3223,12 @@ fi
if [ "$image" != "off" ] && [ "$image" != "ascii" ]; then if [ "$image" != "off" ] && [ "$image" != "ascii" ]; then
case "$image_backend" in case "$image_backend" in
"w3m") "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" $w3m_img_path 2>/dev/null || padding="\033[0C"
;; ;;
"iterm2") "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 esac
fi fi

View file

@ -175,7 +175,9 @@ Image source. Where and what image we display.
Possible values: wall, ascii, /path/to/img, /path/to/dir/, off Possible values: wall, ascii, /path/to/img, /path/to/dir/, off
.TP .TP
.B \--size 'size' .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 .TP
.B \--image_position 'left/right' .B \--image_position 'left/right'
Where to display the image: (Left/Right) Where to display the image: (Left/Right)