Skip to content

Commit

Permalink
OVERLOAD PROTECTION ENCABULATOR!
Browse files Browse the repository at this point in the history
limit active processes to 9
  • Loading branch information
Ryan P.C. McQuen committed Jan 20, 2015
1 parent 9e1090e commit 4117ea8
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions imgult
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ PNGEXTENSIONS="png apng mng"
GIFEXTENSIONS="gif"
SVGEXTENSIONS="svg svgz"

RUN_OVERLOAD_PROTECTION_ENCABULATOR() {
while [ "`jobs | wc -l`" -gt 9 ]; do
wait
echo "*-_-OVERLOAD PROTECTION INITIATED-_-*"
done
}

if [ -z "$JPEGTRAN" ]; then
export PATH=/usr/local/Cellar/mozjpeg/*/bin:/opt/libmozjpeg/bin:/opt/mozjpeg/bin:$PATH
JPEGTRAN="$(which jpegtran)"
Expand Down Expand Up @@ -75,32 +82,42 @@ if [ "$EXIFREMOVE" = "true" ]; then
done
fi

RUN_OVERLOAD_PROTECTION_ENCABULATOR

## standard options with verbosity
egrep -i "($(echo $JPGEXTENSIONS | tr ' ' '|')\$)" imgult-files.txt | \
while read IMGULT_FILE; do
$JPEGTRAN -verbose -outfile "$IMGULT_FILE" "$IMGULT_FILE" \
&& jpegoptim -v -m$OPTLEVEL "$IMGULT_FILE" &
done

RUN_OVERLOAD_PROTECTION_ENCABULATOR

## standard options with verbosity
egrep -i "($(echo $PNGEXTENSIONS | tr ' ' '|')\$)" imgult-files.txt | \
while read IMGULT_FILE; do
pngquant -f -v --skip-if-larger -o "$IMGULT_FILE" -- "$IMGULT_FILE" \
&& optipng -v "$IMGULT_FILE" &
done

RUN_OVERLOAD_PROTECTION_ENCABULATOR

## -b keeps the filename, -O3 uses highest optimization level
## it is an 'O' as in Oxford, not a zero (0)
egrep -i "($(echo $GIFEXTENSIONS | tr ' ' '|')\$)" imgult-files.txt | \
while read IMGULT_FILE; do
gifsicle -V -b -O3 "$IMGULT_FILE" &
done

RUN_OVERLOAD_PROTECTION_ENCABULATOR

egrep -i "($(echo $SVGEXTENSIONS | tr ' ' '|')\$)" imgult-files.txt | \
while read IMGULT_FILE; do
svgo "$IMGULT_FILE"
done

RUN_OVERLOAD_PROTECTION_ENCABULATOR

## let everything complete
while [ -e imgult-files.txt ]; do
if [ "`pgrep egrep`" ] || [ "`pgrep exiv2`" ] \
Expand Down

0 comments on commit 4117ea8

Please sign in to comment.