Skip to content

Instantly share code, notes, and snippets.

View icalrn's full-sized avatar

Faisal Rahman icalrn

View GitHub Profile
@icalrn
icalrn / optimize-images.sh
Created December 8, 2021 02:47
Optimize Images with Imagemin while Preserving Directory Structure
#!/bin/sh
find ./public/images -type f \( -iname \*.jpg -o -iname \*.png -o -iname \*.svg \) | xargs -I % sh -c 'imagemin % -o $(dirname % | sed --expression="s/public/&\/optimized/")'
# `find` - Look for files in the specified path
# -type f - Filter the files to only include regular files
# \( \) - Group statements so that the previous flag (-type f) applies to all following statements
# -iname - Look for files with specified names, case insensitive
# -o - OR operand
#