Add some padding to image to prevent tooltip overlap
This commit is contained in:
parent
f80324659f
commit
88f80f629b
22
xkcdlock
22
xkcdlock
|
@ -48,12 +48,16 @@ BG_COLOUR="white"
|
|||
# Break tooltip every x char to prevent border overflow
|
||||
TOOLTIP_MAX_LINE_LEN=100
|
||||
|
||||
# Reduce image size by x pixels in x and y dimension
|
||||
# so that the tooltip does not overlay image
|
||||
IMAGE_PADDING_PX=100
|
||||
|
||||
FONT="xkcd Script"
|
||||
FONT_FILE="xkcd-script.ttf"
|
||||
FONT_PATH="${HOME}/.local/share/fonts/${FONT_FILE}"
|
||||
URL_FONT="https://github.com/ipython/xkcd-font/raw/master/xkcd-script/font/xkcd-script.ttf"
|
||||
|
||||
declare -a DEPS=("xrandr" "awk" "curl" "convert" "recode" "sed")
|
||||
declare -a DEPS=("xrandr" "awk" "curl" "convert" "fold" "recode" "sed")
|
||||
declare -a DEPS_LOCKER=("i3lock" "swaylock")
|
||||
|
||||
DOWNLOAD_DISCLAIMER="\nThe downloaded images will end up in your current working directory.\n\
|
||||
|
@ -256,11 +260,20 @@ image_add_text() {
|
|||
echo "$tmp_file"
|
||||
}
|
||||
|
||||
target_image_size() {
|
||||
IFS='x'
|
||||
read -a strarr <<< "$1"
|
||||
local img_size_x=`expr "${strarr[0]}" - $IMAGE_PADDING_PX`
|
||||
local img_size_y=`expr "${strarr[1]}" - $IMAGE_PADDING_PX`
|
||||
local img_size="${img_size_x}x${img_size_y}"
|
||||
echo "$img_size"
|
||||
}
|
||||
|
||||
resize_image() {
|
||||
local tmp_file=$(mktemp)
|
||||
|
||||
log "Resizing $img_fn to $res and saving image to $tmp_file"
|
||||
convert -adaptive-resize $res $img_fn $tmp_file
|
||||
log "Resizing $img_fn to $2 and saving image to $tmp_file"
|
||||
convert -adaptive-resize $2 $img_fn $tmp_file
|
||||
|
||||
if ! [[ -e "$tmp_file" ]]; then
|
||||
error "Could not find resized image"
|
||||
|
@ -291,7 +304,8 @@ prepare_image() {
|
|||
local text=$(xkcd_get_img_tooltip $img_nr)
|
||||
img_tooltip=$(xkcd_format_tooltip $text)
|
||||
|
||||
local tmp_file_r=$(resize_image $img_fn $res)
|
||||
local img_target_size=$(target_image_size $res)
|
||||
local tmp_file_r=$(resize_image $img_fn $img_target_size)
|
||||
local tmp_file_c=$(center_image $tmp_file_r $res)
|
||||
local tmp_file_t1=$(image_add_text "${tmp_file_c}" "${img_nr}" "Northeast" "green" "${FONT_PATH}" "+50+50" "50")
|
||||
local tmp_file_t2=$(image_add_text "${tmp_file_t1}" "${img_tooltip}" "Southwest" "red" "${FONT_PATH}" "+0+0" "30" " -undercolor '#00000080' ")
|
||||
|
|
Loading…
Reference in New Issue