use an svg as the base for the mask so scaling it is higher resolution and stored file is smaller. I am not sure why i did this.

This commit is contained in:
Nick Silverman 2020-08-11 19:05:14 +00:00 committed by SillyPill
parent 67eea6306c
commit 2f4e19c297
8 changed files with 37 additions and 19 deletions

View file

@ -21,7 +21,7 @@ I use this script to place the arch logo on all my wallpapers.
## Example 2
![example2](examples/example2.jpg)
![arch btw example2](examples/arch_btw_examplew.jpg)
![arch btw example2](examples/arch_btw_example2.jpg)
## Example 3
![example3](examples/example3.jpg)

BIN
arch.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

1
arch.svg Normal file
View file

@ -0,0 +1 @@
<?xml version="1.0" ?><svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title/><path id="svg_1" d="m12.01523,0.66759c-1.01457,2.48659 -1.62594,4.11341 -2.7551,6.52653c0.69271,0.7347 1.54286,1.58921 2.92303,2.55394c-1.48425,-0.6105 -2.49621,-1.22362 -3.25277,-1.85948c-1.4449,3.01575 -3.7102,7.31195 -8.30554,15.56851c3.61225,-2.08513 6.41196,-3.36996 9.02099,-3.86151c-0.11195,-0.48105 -0.1758,-1.00321 -0.17143,-1.54723l0.0035,-0.11545c0.05773,-2.31429 1.26123,-4.09417 2.68688,-3.9726c1.42566,0.11983 2.53383,2.09563 2.47785,4.40904c-0.0105,0.43557 -0.06035,0.85452 -0.14607,1.24286c2.58105,0.50466 5.3519,1.78688 8.91429,3.84402c-0.70233,-1.29271 -1.32945,-2.4586 -1.92857,-3.56939c-0.94373,-0.73119 -1.92682,-1.6828 -3.93324,-2.71312c1.3793,0.3586 2.36677,0.77143 3.13644,1.23411c-6.09008,-11.3344 -6.58163,-12.8414 -8.67026,-17.74023z"/></svg>

After

Width:  |  Height:  |  Size: 871 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 344 KiB

After

Width:  |  Height:  |  Size: 338 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 591 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 864 KiB

After

Width:  |  Height:  |  Size: 828 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 589 KiB

View file

@ -2,27 +2,44 @@
pape=$1
# Get the width of the wallpaper
height=$(magick convert "$pape" -format "%h" info:)
width=$(magick convert "$pape" -format "%w" info:)
# get the width of the wallpaper
height=$(magick identify -format "%h" "$pape")
width=$(magick identify -format "%w" "$pape")
# Calculate appropriate height for logo on the wallpaper
logo_height=$(($height*9/16))
# determine smaller dimension to use for scale
if [[ "$height" -lt "$width" ]]; then
scale_val=$height
else
scale_val=$width
fi
# Generate Mask
convert "./arch.png" -gravity center -resize $logo_height -background white -extent "${width}x${height}" -flatten "temp_logo.png"
# 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}")
# Generate Wallpaper
# generate a PNG mask from the source svg
convert \
-density $density \
-gravity center \
-background white \
-extent "${width}x${height}" \
arch.svg \
tmp_arch_mask.png
# generate wallpaper name
outfile_name=$(basename "$pape")
convert "$pape" -write-mask "temp_logo.png" -gravity center \
# add arch mask to original image
convert \
-write-mask "tmp_arch_mask.png" \
-gravity center \
-blur 0x30 \
-attenuate 0.3 +noise Laplacian\
-attenuate 0.3 \
+noise Laplacian \
-evaluate Multiply 1.3 \
"$pape" \
"arch_btw_$outfile_name"
# Delete temporary file
rm "temp_logo.png"
# TODO: imagemagick giving colorspace warning
# TODO: Use SVG instead of png?
# delete temporary file
rm "tmp_arch_mask.png"