diff --git a/arch.svg b/logo/arch.svg similarity index 100% rename from arch.svg rename to logo/arch.svg diff --git a/mepapemaker.sh b/mepapemaker.sh index ee50cb4..d97a68a 100755 --- a/mepapemaker.sh +++ b/mepapemaker.sh @@ -1,46 +1,73 @@ #!/usr/bin/bash -pape=$1 +logo=$1 +pape=$2 -# get the width of the wallpaper -height=$(magick identify -format "%h" "$pape") -width=$(magick identify -format "%w" "$pape") +if [[ -z "$logo" ]] || [[ -z "$pape" ]]; then + echo $'Usage: ./mepapemaker.sh \n\n is the logo name without the svg file extension.\nFor , all image formats supported by\nImageMagick are valid targets.' + exit +fi + +if [ ! -f "./logo/$logo.svg" ]; then + echo $'No such logo found.\nCheck the logo directory for available options or add\nyour own .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 -if [[ "$height" -lt "$width" ]]; then - scale_val=$height +if [[ "$lheight" -lt "$lwidth" ]]; then + lscale_val=$lheight 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 # calculate appropriate density to scale 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 %) -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 magick \ -density $density \ -gravity center \ - arch.svg \ + ./logo/$logo.svg \ -background white \ - -extent "${width}x${height}" \ + -extent "${pwidth}x${pheight}" \ -resize 100% \ - tmp_arch_mask.png + tmp_mask.png # generate wallpaper name -outfile_name=$(basename "$pape") +outfile_name=${logo}_btw_$(basename "$pape") # add arch mask to original image magick \ "$pape" \ - -write-mask "tmp_arch_mask.png" \ + -write-mask "tmp_mask.png" \ -gravity center \ -blur 0x30 \ -attenuate 0.3 \ +noise Laplacian \ -evaluate Multiply 1.3 \ - "arch_btw_$outfile_name" + "$outfile_name" # delete temporary file -rm "tmp_arch_mask.png" +rm "tmp_mask.png"