summaryrefslogtreecommitdiff
path: root/CLI/reduce-image-sizes.sh
diff options
context:
space:
mode:
Diffstat (limited to 'CLI/reduce-image-sizes.sh')
-rw-r--r--CLI/reduce-image-sizes.sh36
1 files changed, 36 insertions, 0 deletions
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