Add a launch flag and a config option inside the script to change the crop offset

This commit is contained in:
dylan araps 2015-12-30 22:30:43 +11:00
parent 78fdeb0c2a
commit e8c9026f5e
2 changed files with 21 additions and 7 deletions

View File

@ -66,6 +66,9 @@ These are the script's optional dependencies
The image gets priority over other The image gets priority over other
images: (wallpaper, \$img) images: (wallpaper, \$img)
--size px Change the size of the image --size px Change the size of the image
--cropoffset value Change the crop offset. Possible values:
northwest, north, northeast, west, center
east, southwest, south, southeast"
--padding How many spaces to pad the text --padding How many spaces to pad the text
to the right to the right
--xoffset px How close the image will be --xoffset px How close the image will be

View File

@ -82,6 +82,11 @@ imgsize=128
yoffset=0 yoffset=0
xoffset=0 xoffset=0
# Default crop offset (Customizable at launch with --cropoffset)
# Possible values:
# NorthWest, north, northEast, west, center, east, southwest, south, southeast
crop_offset="center"
# Padding to align text to the right # Padding to align text to the right
# TODO: Find a reliable way to set this dynamically. I can get # TODO: Find a reliable way to set this dynamically. I can get
# this to work based on font width but there's no reliable way # this to work based on font width but there's no reliable way
@ -231,6 +236,10 @@ usage () {
echo " The image gets priority over other" echo " The image gets priority over other"
echo " images: (wallpaper, \$img)" echo " images: (wallpaper, \$img)"
echo " --size px Change the size of the image" echo " --size px Change the size of the image"
echo " --cropoffset value Change the crop offset. Possible values:"
echo " northwest, north, northeast, west, center"
echo " east, southwest, south, southeast"
echo
echo " --padding How many spaces to pad the text" echo " --padding How many spaces to pad the text"
echo " to the right" echo " to the right"
echo " --xoffset px How close the image will be " echo " --xoffset px How close the image will be "
@ -250,6 +259,7 @@ usage () {
# }}} # }}}
# Args {{{ # Args {{{
@ -293,6 +303,7 @@ for argument in $args; do
# Image # Image
--image) usewall=0; img="$2" ;; --image) usewall=0; img="$2" ;;
--size) imgsize="$2" ;; --size) imgsize="$2" ;;
--cropoffset) crop_offset="$2" ;;
--padding) pad="$2" ;; --padding) pad="$2" ;;
--xoffset) xoffset="$2" ;; --xoffset) xoffset="$2" ;;
--yoffset) yoffset="$2" ;; --yoffset) yoffset="$2" ;;
@ -322,14 +333,14 @@ if [ $enableimages -eq 1 ]; then
[ $usewall -eq 1 ] && \ [ $usewall -eq 1 ] && \
img=$(awk '/feh/ {printf $3}' "$HOME/.fehbg" | sed -e "s/'//g") img=$(awk '/feh/ {printf $3}' "$HOME/.fehbg" | sed -e "s/'//g")
# Get name of image # Get name of image and prefix it with it's crop offset
imgname=${img##*/} imgname="$crop_offset-${img##*/}"
# If the image in the tempdir is a different size to $imgsize, delete it
# This check allows you to resize the image at launch # This check allows you to resize the image at launch
[ -f "$imgtempdir/$imgname" ] && \ if [ -f "$imgtempdir/$imgname" ]; then
[ $(identify -format "%h" "$imgtempdir/$imgname") != $imgsize ] && \ imgheight=$(identify -format "%h" "$imgtempdir/$imgname")
rm "$imgtempdir/$imgname" [ $imgheight != $imgsize ] && rm "$imgtempdir/$imgname"
fi
# Check to see if the tempfile exists before we do any cropping. # Check to see if the tempfile exists before we do any cropping.
if [ ! -f "$imgtempdir/$imgname" ]; then if [ ! -f "$imgtempdir/$imgname" ]; then
@ -356,7 +367,7 @@ if [ $enableimages -eq 1 ]; then
# of a tiny image. # of a tiny image.
convert \ convert \
-crop "$size"x"$size"+0+0 \ -crop "$size"x"$size"+0+0 \
-gravity center "$img" \ -gravity $crop_offset "$img" \
-resize "$imgsize"x"$imgsize" "$imgtempdir/$imgname" -resize "$imgsize"x"$imgsize" "$imgtempdir/$imgname"
fi fi