Skip to content

Commit

Permalink
feat(pngquant): add --skip-if-larger option
Browse files Browse the repository at this point in the history
It is extremely unstable when quality range is 0-100, disregarding
almost all gains superior to 60% as "too lossy".
  • Loading branch information
Fernando Barros authored and JamieMason committed Feb 9, 2016
1 parent 908327a commit 9904253
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 29 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,16 @@ these guides.

Options:

-d, --directory directory of images to process
-a, --image-alpha pre-process PNGs with ImageAlpha.app *
-j, --jpeg-mini pre-process JPGs with JPEGmini.app **
-m, --min-quality pngquant min quality parameter
-q, --quit quit all apps when complete
-c, --no-color disable color output
-h, --help display this usage information
-e, --examples display some example commands and uses
-v, --version display the version number
-d, --directory directory of images to process
-a, --image-alpha pre-process PNGs with ImageAlpha.app *
-j, --jpeg-mini pre-process JPGs with JPEGmini.app **
-m, --min-quality pngquant min quality parameter
-s, --skip-if-larger pngquant use --skip-if-larger
-q, --quit quit all apps when complete
-c, --no-color disable color output
-h, --help display this usage information
-e, --examples display some example commands and uses
-v, --version display the version number

* http://pngmini.com
** https://itunes.apple.com/us/app/jpegmini/id498944723
Expand Down
3 changes: 3 additions & 0 deletions bin/imageOptim
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ while [ "$1" != "" ]; do
shift;
MIN_QUALITY="$1"
;;
-s | --skip-if-larger )
SKIP_IF_LARGER="true"
;;
-q | --quit )
QUIT_ON_COMPLETE="true"
;;
Expand Down
28 changes: 18 additions & 10 deletions bin/imageOptimBashLib
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ DIRECTORY_OPTION="false"
# {Number} Optinally overriden with -m or --min-quality
MIN_QUALITY="75"

# {BooleanString} Optionally use -s or --skip-if-larger with pngquant
SKIP_IF_LARGER="false"

# {BooleanString} Optionally overridden with -a or --image-alpha.
USE_IMAGE_ALPHA="false"

Expand Down Expand Up @@ -128,15 +131,16 @@ function usage {
echo ""
echo "Options:"
echo ""
echo " -d, --directory directory of images to process"
echo " -a, --image-alpha pre-process PNGs with ImageAlpha.app *"
echo " -j, --jpeg-mini pre-process JPGs with JPEGmini.app **"
echo " -m, --min-quality pngquant min quality parameter"
echo " -q, --quit quit all apps when complete"
echo " -c, --no-color disable color output"
echo " -h, --help display this usage information"
echo " -e, --examples display some example commands and uses"
echo " -v, --version display the version number"
echo " -d, --directory directory of images to process"
echo " -a, --image-alpha pre-process PNGs with ImageAlpha.app *"
echo " -j, --jpeg-mini pre-process JPGs with JPEGmini.app **"
echo " -m, --min-quality pngquant min quality parameter"
echo " -s, --skip-if-larger pngquant use --skip-if-larger"
echo " -q, --quit quit all apps when complete"
echo " -c, --no-color disable color output"
echo " -h, --help display this usage information"
echo " -e, --examples display some example commands and uses"
echo " -v, --version display the version number"
echo ""
echo "* http://pngmini.com"
echo "** https://itunes.apple.com/us/app/jpegmini/id498944723"
Expand Down Expand Up @@ -463,7 +467,11 @@ function get_jpegmini_app_name {
function run_image_alpha {
if [ "true" == "$USE_IMAGE_ALPHA" ]; then
info "Running ImageAlpha..."
find "${TEMP_PATH}/png" -type f -print0 | xargs -n10 -P8 -0 "$PNGQUANT_PATH" --ext=.png --force --speed=1 --quality="$MIN_QUALITY"-100 --skip-if-larger --
local added_options
if [ "true" == "$SKIP_IF_LARGER" ]; then
added_options="--skip-if-larger"
fi
find "${TEMP_PATH}/png" -type f -print0 | xargs -n10 -P8 -0 "$PNGQUANT_PATH" --ext=.png --force --speed=1 --quality="$MIN_QUALITY"-100 ${added_options} --
fi
}

Expand Down
3 changes: 3 additions & 0 deletions src/imageOptim
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ while [ "$1" != "" ]; do
shift;
MIN_QUALITY="$1"
;;
-s | --skip-if-larger )
SKIP_IF_LARGER="true"
;;
-q | --quit )
QUIT_ON_COMPLETE="true"
;;
Expand Down
9 changes: 8 additions & 1 deletion src/imageOptimBashLib
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ DIRECTORY_OPTION="false"
# {Number} Optinally overriden with -m or --min-quality
MIN_QUALITY="75"

# {BooleanString} Optionally use -s or --skip-if-larger with pngquant
SKIP_IF_LARGER="false"

# {BooleanString} Optionally overridden with -a or --image-alpha.
USE_IMAGE_ALPHA="false"

Expand Down Expand Up @@ -407,7 +410,11 @@ function get_jpegmini_app_name {
function run_image_alpha {
if [ "true" == "$USE_IMAGE_ALPHA" ]; then
info "Running ImageAlpha..."
find "${TEMP_PATH}/png" -type f -print0 | xargs -n10 -P8 -0 "$PNGQUANT_PATH" --ext=.png --force --speed=1 --quality="$MIN_QUALITY"-100 --skip-if-larger --
local added_options
if [ "true" == "$SKIP_IF_LARGER" ]; then
added_options="--skip-if-larger"
fi
find "${TEMP_PATH}/png" -type f -print0 | xargs -n10 -P8 -0 "$PNGQUANT_PATH" --ext=.png --force --speed=1 --quality="$MIN_QUALITY"-100 ${added_options} --
fi
}

Expand Down
19 changes: 10 additions & 9 deletions src/usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ Usage: imageoptim [options]

Options:

-d, --directory directory of images to process
-a, --image-alpha pre-process PNGs with ImageAlpha.app *
-j, --jpeg-mini pre-process JPGs with JPEGmini.app **
-m, --min-quality pngquant min quality parameter
-q, --quit quit all apps when complete
-c, --no-color disable color output
-h, --help display this usage information
-e, --examples display some example commands and uses
-v, --version display the version number
-d, --directory directory of images to process
-a, --image-alpha pre-process PNGs with ImageAlpha.app *
-j, --jpeg-mini pre-process JPGs with JPEGmini.app **
-m, --min-quality pngquant min quality parameter
-s, --skip-if-larger pngquant use --skip-if-larger
-q, --quit quit all apps when complete
-c, --no-color disable color output
-h, --help display this usage information
-e, --examples display some example commands and uses
-v, --version display the version number

* http://pngmini.com
** https://itunes.apple.com/us/app/jpegmini/id498944723

0 comments on commit 9904253

Please sign in to comment.