From ac93ed4d29dd85409fb4c0cd9c2af266e90777c1 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sat, 19 Oct 2024 10:04:14 +0200 Subject: initial commit --- CLI/reduce-image-sizes.sh | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 CLI/reduce-image-sizes.sh (limited to 'CLI/reduce-image-sizes.sh') diff --git a/CLI/reduce-image-sizes.sh b/CLI/reduce-image-sizes.sh new file mode 100644 index 0000000..3bad2a2 --- /dev/null +++ b/CLI/reduce-image-sizes.sh @@ -0,0 +1,36 @@ +# mogrify -resize 3840x2160 *.jpg + +# jpeg to jpg +find . -type f -iregex ".*\.jpe?g" -exec mogrify -format jpg {} \; + +# resize everything to max 4k +# TODO: also scales up... but shouldn't! +find . -type f -regextype posix-extended -iregex ".*\.(png|jpe?g|gif|webp)" -exec mogrify -resize 3840x2160 {} \; +find . -type f -regextype posix-extended -iregex ".*\.(png|jpe?g|gif|webp)" -exec mogrify -resize 1920x1080 {} \; +find . -type f -regextype posix-extended -iregex ".*\.(png|jpe?g|gif|webp)" -exec mogrify -resize 1200x675 {} \; + +# optimize jpg +find . -type f -iregex ".*\.jpe?g" -exec jpegoptim --strip-all {} \; +find . -type f -iname "*.jpg" -exec jpegoptim --strip-all {} \; + +# optimize png +find . -type f -iname "*.png" -exec optipng -o5 {} \; + +# convert to webp +find . -type f -regextype posix-extended -iregex ".*\.(png|jpe?g)" -exec convert {} -quality 90 -define webp:lossless=true $(echo {} | cut -d . -f 1).webp \; + +# add border to image +convert $img.png -background none -bordercolor none -border 20 $img.png + +# square image for favicon +# order of things is important +convert $img -background none -thumbnail 64x64^ -gravity center -extent ${longestside}x${x} $img + +# crop image to size - from center +# https://www.imagemagick.org/discourse-server/viewtopic.php?t=13793 +convert $img -resize 1200x900^ -gravity center -crop 1200x900+0+0 $img + +# svg to png +convert -scale ${x}x${y} -extent 110%x110% -gravity center -background transparent $svg $png +# https://stackoverflow.com/a/12690135 +convert -density 1200 -resize 200x -background none $svg $png -- cgit v1.2.3