make script generic and rename it

This commit is contained in:
tastytea 2022-06-12 04:09:00 +02:00
parent fba286cfc7
commit 61604461a1
Signed by: tastytea
SSH Key Fingerprint: SHA256:FBkvrOlhq5use1XEttyUGT4bUTDVA1ar9SgIc9P03cM
3 changed files with 25 additions and 21 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
/webp/
/png/

24
generate_raster_images.zsh Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env zsh
# Generates trimmed raster images images from SVGs in svg/.
# Argument 1 is the file extension, default is webp.
# Argument 2 is the size, default is to use the SVG size.
setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL
if ! type convert &> /dev/null; then
print -u2 "'convert' from imagemagick not found"
return 1
fi
local ext=webp
[[ ${ARGC} > 0 ]] && ext=${1}
local size=-1
[[ ${ARGC} > 1 ]] && size=${2}
print "generating ${ext} images in ${PWD}/${ext}"
mkdir -p ${ext}
for svg in svg/*.svg; do
local target=${svg##*/}
target=${ext}/${target%.*}.${ext}
convert ${svg} -trim -resize ${size} -quality 100 -verbose ${target}
done

View File

@ -1,21 +0,0 @@
#!/usr/bin/env zsh
# Generates trimmed WebP images from SVGs in svg/.
# First argument is the size, default is to use the SVG size.
setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL
if ! type convert &> /dev/null; then
print -u2 "'convert' from imagemagick not found"
return 1
fi
local size=-1
[[ ${ARGC} > 0 ]] && size=${1}
print "generating WebP images in ${PWD}/webp …"
mkdir -p webp
for svg in svg/*.svg; do
local webp=${svg##*/}
webp=webp/${webp%.*}.webp
convert ${svg} -trim -resize ${size} -quality 100 -verbose ${webp}
done