Skip to content

fjcaetano/xcode-png-optim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

5 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿž xcode-png-optim homebrew PRs welcome

Scans an Xcode target for PNGs and converts all to optimized JPEGs. If an image's directory contains a Contents.json file, xcode-png-optim understands it's within an Assets.xcassets catalog and will update the JSON file accordingly.

By default, xcode-png-optim will convert only non-transparent PNGs. If you need to tweak the tolerance level for the alpha channel of each image, use the --alpha-tolerance argument. The tolerance must be a value between zero and one, where 0 is no tolerance (e.g. if an image has any transparency at all, it will be ignored) and 1 is full tolerance (e.g. all PNGs will be converted, regardless of transparency levels).

Installation

Assuming that you have Homebrew installed, execute the following steps:

  1. Use this repository as a "tap" (alternative package repository):
$ brew tap fjcaetano/xcode-png-optim
  1. Install xcode-png-optim (and dependencies):
$ brew install xcode-png-optim

Automatically converting using a build script (optional)

If you want Xcode to automatically convert PNGs added to assets catalogs, add the following Build Script to the desired target before the Copy Bundle Resources phase.

if which xcode-png-optim >/dev/null; then
  xcode-png-optim "$SOURCE_ROOT/$TARGET_NAME"
else
  echo "error: xcode-png-optim not installed, download from https://github.com/fjcaetano/xcode-png-optim"
  exit 1
fi

Notice that the script above will fail the build process if xcode-png-optim is not installed. If that's not desirable, remove the exit 1 line and change the message from error: ... to warning: ...

Usage

$ xcode-png-optim [options] {dir_name}
Options Description Default value
-t, --alpha-tolerance The tolerance allowed for the alpha channel. Value must be 0...1 0
-x, --no-xcode-log Do not format output for Xcode. When this is set, the output will include ANSI colors N/A
-c, --no-update-contents Do not update Content.json files N/A
-i, --ignore-cache Ignores the cached files N/A
-f, --force Forces the convertion, overwriting existing files N/A
-h, --help Prints helper message N/A
-v, --version Prints current version N/A

If no dir_name is given, the optimization will use the current directory.