Image: Rename $img to $image

This commit is contained in:
Dylan Araps 2016-11-13 15:33:28 +11:00
parent a1b79bd33b
commit e262e30d93

View file

@ -1815,18 +1815,18 @@ get_image_backend() {
*) *)
if [[ -d "$image_source" ]]; then if [[ -d "$image_source" ]]; then
files=("${image_source%/}"/*.{png,jpg,jpeg}) files=("${image_source%/}"/*.{png,jpg,jpeg})
img="$(printf "%s" "${files[RANDOM % (${#files[@]} - 1)]}")" image="$(printf "%s" "${files[RANDOM % (${#files[@]} - 1)]}")"
else else
img="$image_source" image="$image_source"
fi fi
;; ;;
esac esac
# Fallback to ascii mode if image isn't a file. # Fallback to ascii mode if image isn't a file.
if [[ ! -f "$img" ]]; then if [[ ! -f "$image" ]]; then
image_backend="ascii" image_backend="ascii"
get_ascii 2>/dev/null get_ascii 2>/dev/null
err "Image: '$img', doesn't exist, falling back to ascii mode." err "Image: '$image', doesn't exist, falling back to ascii mode."
return return
fi fi
@ -1885,14 +1885,15 @@ get_ascii() {
get_script_dir 2>/dev/null get_script_dir 2>/dev/null
# If the ascii file doesn't exist fallback to text mode. # If the ascii file doesn't exist fallback to text mode.
if [[ ! -f "$script_dir/ascii/distro/${ascii/ *}" ]]; then if [[ -f "$script_dir/ascii/distro/${ascii/ *}" ]]; then
ascii="$script_dir/ascii/distro/${ascii/ *}"
else
text_padding="0" text_padding="0"
image="off" image_backend="off"
err "Ascii: Ascii file not found, falling back to text mode." err "Ascii: Ascii file not found, falling back to text mode."
return return
fi fi
ascii="$script_dir/ascii/distro/${ascii/ *}"
fi fi
fi fi
@ -1952,52 +1953,52 @@ get_wallpaper() {
case "$os" in case "$os" in
"Linux" | "BSD") "Linux" | "BSD")
if type -p feh >/dev/null && [[ -f "$HOME/.fehbg" ]]; then if type -p feh >/dev/null && [[ -f "$HOME/.fehbg" ]]; then
img="$(awk -F\' '/feh/ {printf $2}' "$HOME/.fehbg")" image="$(awk -F\' '/feh/ {printf $2}' "$HOME/.fehbg")"
elif type -p nitrogen >/dev/null; then elif type -p nitrogen >/dev/null; then
img="$(awk -F'=' '/file/ {printf $2;exit;}' "$XDG_CONFIG_HOME/nitrogen/bg-saved.cfg")" image="$(awk -F'=' '/file/ {printf $2;exit;}' "$XDG_CONFIG_HOME/nitrogen/bg-saved.cfg")"
elif type -p gsettings >/dev/null; then elif type -p gsettings >/dev/null; then
# Get DE if user has disabled the function. # Get DE if user has disabled the function.
[[ -z "$de" ]] && get_de [[ -z "$de" ]] && get_de
case "$de" in case "$de" in
"MATE"*) img="$(gsettings get org.mate.background picture-filename)" ;; "MATE"*) image="$(gsettings get org.mate.background picture-filename)" ;;
*) img="$(gsettings get org.gnome.desktop.background picture-uri)" ;; *) image="$(gsettings get org.gnome.desktop.background picture-uri)" ;;
esac esac
# Strip quotes etc from the path. # Strip quotes etc from the path.
img="${img/'file://'}" image="${image/'file://'}"
img="${img//\'}" image="${image//\'}"
img="${img//\%20/ }" image="${image//\%20/ }"
fi fi
;; ;;
"Mac OS X") "Mac OS X")
img="$(osascript -e 'tell application "System Events" to picture of current desktop')" image="$(osascript -e 'tell application "System Events" to picture of current desktop')"
;; ;;
"Windows") "Windows")
case "$distro" in case "$distro" in
"Windows XP") "Windows XP")
img="/cygdrive/c/Documents and Settings/${USER}" image="/cygdrive/c/Documents and Settings/${USER}"
img+="/Local Settings/Application Data/Microsoft" image+="/Local Settings/Application Data/Microsoft"
img+="/Wallpaper1.bmp" image+="/Wallpaper1.bmp"
;; ;;
"Windows"*) "Windows"*)
img="$APPDATA/Microsoft/Windows/Themes" image="$APPDATA/Microsoft/Windows/Themes"
img+="/TranscodedWallpaper.jpg" image+="/TranscodedWallpaper.jpg"
;; ;;
esac esac
;; ;;
esac esac
# If img is an xml file don't use it. # If image is an xml file don't use it.
[[ "${img/*\./}" == "xml" ]] && img="" [[ "${image/*\./}" == "xml" ]] && image=""
# Error msg # Error msg
[[ -z "$img" ]] && err "Image: Wallpaper detection failed, falling back to ascii mode." [[ ! -f "$image" ]] && err "Image: Wallpaper detection failed, falling back to ascii mode."
} }
get_term_size() { get_term_size() {
@ -2073,7 +2074,7 @@ get_term_size() {
fi fi
fi fi
# If $img isn't a file fallback to ascii mode. # If $image isn't a file fallback to ascii mode.
if [[ "$term_width" ]] && ((term_width > 0)); then if [[ "$term_width" ]] && ((term_width > 0)); then
clear clear
zws=" " zws=" "
@ -2117,7 +2118,7 @@ get_image_size() {
"none") "none")
# 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")" size="$(identify -format "%w %h" "$image")"
width="${size%% *}" width="${size%% *}"
height="${size##* }" height="${size##* }"
crop_mode="none" crop_mode="none"
@ -2135,23 +2136,23 @@ get_image_size() {
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.
imgname="$crop_mode-$crop_offset-$width-$height" image_name="$crop_mode-$crop_offset-$width-$height"
# Check to see if the image has a file extension, # Check to see if the image has a file extension,
# if it doesn't then add one. # if it doesn't then add one.
case "${img##*/}" in case "${image##*/}" in
*"."*) imgname="${imgname}-${img##*/}" ;; *"."*) image_name="${image_name}-${image##*/}" ;;
*) imgname="${imgname}-${img##*/}.jpg" ;; *) image_name="${image_name}-${image##*/}.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/$image_name" ]]; then
# 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"
# Get image size so that we can do a better crop # Get image size so that we can do a better crop
if [[ -z "$size" ]]; then if [[ -z "$size" ]]; then
size="$(identify -format "%w %h" "$img")" size="$(identify -format "%w %h" "$image")"
og_width="${size%% *}" og_width="${size%% *}"
og_height="${size##* }" og_height="${size##* }"
@ -2163,44 +2164,44 @@ make_thumbnail() {
case "$crop_mode" in case "$crop_mode" in
"fit") "fit")
c="$(convert "$img" \ c="$(convert "$image" \
-colorspace srgb \ -colorspace srgb \
-format "%[pixel:p{0,0}]" info:)" -format "%[pixel:p{0,0}]" info:)"
convert \ convert \
"$img" \ "$image" \
-trim +repage \ -trim +repage \
-gravity south \ -gravity south \
-background "$c" \ -background "$c" \
-extent "$size"x"$size" \ -extent "$size"x"$size" \
-scale "$width"x"$height" \ -scale "$width"x"$height" \
"$thumbnail_dir/$imgname" "$thumbnail_dir/$image_name"
;; ;;
"fill") "fill")
convert \ convert \
"$img" \ "$image" \
-trim +repage \ -trim +repage \
-scale "$width"x"$height"^ \ -scale "$width"x"$height"^ \
-extent "$width"x"$height" \ -extent "$width"x"$height" \
"$thumbnail_dir/$imgname" "$thumbnail_dir/$image_name"
;; ;;
"none") cp "$img" "$thumbnail_dir/$imgname" ;; "none") cp "$image" "$thumbnail_dir/$image_name" ;;
*) *)
convert \ convert \
"$img" \ "$image" \
-gravity "$crop_offset" \ -gravity "$crop_offset" \
-crop "$size"x"$size"+0+0 \ -crop "$size"x"$size"+0+0 \
-quality 95 \ -quality 95 \
-scale "$width"x"$height" \ -scale "$width"x"$height" \
"$thumbnail_dir/$imgname" "$thumbnail_dir/$image_name"
;; ;;
esac esac
fi fi
# The final image # The final image
img="$thumbnail_dir/$imgname" image="$thumbnail_dir/$image_name"
} }
display_image() { display_image() {
@ -2209,16 +2210,16 @@ display_image() {
# Add a tiny delay to fix issues with images not # Add a tiny delay to fix issues with images not
# appearing in specific terminal emulators. # appearing in specific terminal emulators.
sleep 0.05 sleep 0.05
printf "%b\n" "0;1;$xoffset;$yoffset;$width;$height;;;;;$img\n4;\n3;" |\ printf "%b\n" "0;1;$xoffset;$yoffset;$width;$height;;;;;$image\n4;\n3;" |\
"$w3m_img_path" -bg "$background_color" >/dev/null & 2>&1 || text_padding="0" "$w3m_img_path" -bg "$background_color" >/dev/null & 2>&1 || text_padding="0"
;; ;;
"iterm2") "iterm2")
printf "%b\a\n" "\033]1337;File=width=${width}px;height=${height}px;inline=1:$(base64 < "$img")" printf "%b\a\n" "\033]1337;File=width=${width}px;height=${height}px;inline=1:$(base64 < "$image")"
;; ;;
"tycat") "tycat")
tycat "$img" tycat "$image"
;; ;;
esac esac
} }
@ -3086,7 +3087,7 @@ get_args() {
;; ;;
--ascii_distro) --ascii_distro)
image="ascii" image_backend="ascii"
ascii_distro="$2" ascii_distro="$2"
case "$2" in "-"* | "") ascii_distro="$distro" ;; esac case "$2" in "-"* | "") ascii_distro="$distro" ;; esac
;; ;;
@ -3094,7 +3095,7 @@ get_args() {
--ascii_logo_size) ascii_logo_size="$2" ;; --ascii_logo_size) ascii_logo_size="$2" ;;
--ascii_bold) ascii_bold="$2" ;; --ascii_bold) ascii_bold="$2" ;;
--logo | -L) --logo | -L)
image="ascii" image_backend="ascii"
print_info() { info line_break; } print_info() { info line_break; }
;; ;;