moved logo svg to its own folder, modified script to enable use of other logos and added error and usage messages

This commit is contained in:
Siren 2025-01-02 13:55:34 +01:00
parent a3e681c85e
commit 50b6585cd8
2 changed files with 42 additions and 15 deletions

View file

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Before After
Before After

View file

@ -1,46 +1,73 @@
#!/usr/bin/bash #!/usr/bin/bash
pape=$1 logo=$1
pape=$2
# get the width of the wallpaper if [[ -z "$logo" ]] || [[ -z "$pape" ]]; then
height=$(magick identify -format "%h" "$pape") echo $'Usage: ./mepapemaker.sh <logo> <wallpaper>\n\n<logo> is the logo name without the svg file extension.\nFor <wallpaper>, all image formats supported by\nImageMagick are valid targets.'
width=$(magick identify -format "%w" "$pape") exit
fi
if [ ! -f "./logo/$logo.svg" ]; then
echo $'No such logo found.\nCheck the logo directory for available options or add\nyour own <logo>.svg to the directory.'
exit
fi
if [ ! -f "$pape" ]; then
echo $'Wallpaper not found. Maybe you mistyped?'
exit
fi
# get the width and height of the logo
lheight=$(magick identify -format "%h" "./logo/$logo.svg")
lwidth=$(magick identify -format "%w" "./logo/$logo.svg")
# determine smaller dimension to use for scale # determine smaller dimension to use for scale
if [[ "$height" -lt "$width" ]]; then if [[ "$lheight" -lt "$lwidth" ]]; then
scale_val=$height lscale_val=$lheight
else else
scale_val=$width lscale_val=$lwidth
fi
# get the width and height of the wallpaper
pheight=$(magick identify -format "%h" "$pape")
pwidth=$(magick identify -format "%w" "$pape")
# determine smaller dimension to use for scale
if [[ "$pheight" -lt "$pwidth" ]]; then
pscale_val=$pheight
else
pscale_val=$pwidth
fi fi
# calculate appropriate density to scale the svg # calculate appropriate density to scale the svg
# 25 is the dimension of either side of the svg # 25 is the dimension of either side of the svg
# 50 is the rough scale of the logo that will be on the final image (in %) # 50 is the rough scale of the logo that will be on the final image (in %)
density=$(awk "BEGIN {print ($scale_val/25.0)*50}") density=$(awk "BEGIN {print ($pscale_val/($lscale_val+2).0)*50}")
# generate a PNG mask from the source svg # generate a PNG mask from the source svg
magick \ magick \
-density $density \ -density $density \
-gravity center \ -gravity center \
arch.svg \ ./logo/$logo.svg \
-background white \ -background white \
-extent "${width}x${height}" \ -extent "${pwidth}x${pheight}" \
-resize 100% \ -resize 100% \
tmp_arch_mask.png tmp_mask.png
# generate wallpaper name # generate wallpaper name
outfile_name=$(basename "$pape") outfile_name=${logo}_btw_$(basename "$pape")
# add arch mask to original image # add arch mask to original image
magick \ magick \
"$pape" \ "$pape" \
-write-mask "tmp_arch_mask.png" \ -write-mask "tmp_mask.png" \
-gravity center \ -gravity center \
-blur 0x30 \ -blur 0x30 \
-attenuate 0.3 \ -attenuate 0.3 \
+noise Laplacian \ +noise Laplacian \
-evaluate Multiply 1.3 \ -evaluate Multiply 1.3 \
"arch_btw_$outfile_name" "$outfile_name"
# delete temporary file # delete temporary file
rm "tmp_arch_mask.png" rm "tmp_mask.png"