Skip to content

Benny-/apng2webp

Repository files navigation

apng2webp

macOS and Linux Build Windows Build

Convert your animated png files to animated webp files.

Usage

usage: apng2webp [-h] [-l [LOOP]] [-bg [BGCOLOR]] [-tmp [TMPDIR]]
                    input [output]

Convert animated png files (apng) to animated webp files.

positional arguments:
  input                 Input path. Must be a .png file.
  output                Output path. If output file already exist it will be
                        overwritten.

optional arguments:
  -h, --help            show this help message and exit
  -l [LOOP], --loop [LOOP]
                        Passed to webpmux. The amount of times the animation
                        should loop. 0 to 65535. Zero indicates to loop
                        forever.
  -bg [BGCOLOR], --bgcolor [BGCOLOR]
                        Passed to webpmux. The background color as a A,R,G,B
                        tuple. Example: 255,255,255,255
  -tmp [TMPDIR], --tmpdir [TMPDIR]
                        A temp directory (it may already exist) to save the
                        temp files during converting, including the extracted
                        PNG images, the metadata and the converted WebP static
                        images for each frame. If not provided, it will use
                        the system temp path and remove temp images after
                        executing.

Examples

apng2webp ./input.png
apng2webp ./input.png ./output.webp
apng2webp -loop 3 -bgcolor 255,255,255,255 -tmpdir ./ ./input.png ./output.webp

Dependencies

  • python (python 2 or 3 can be used)
  • cmake
  • libpng
  • zlib
  • jsoncpp
  • pip (a python package used during installation)
  • The cwebp program must be in your PATH
  • The webpmux program must be in your PATH

Release

If you prefer to use the static linking precompiled binary but not build from source, go to the release page and download apng2webp_dependencies for your platform. Then add the extracted folder to your PATH.

You also need python and pip installed, make sure cwebp and webpmux from webp to be in your PATH. Then check the installation part to install.

Build Setup

macOS

  • Use easy_install to install pip.
  • Use Homebrew to install all the dependencies.
sudo easy_install pip
brew update
brew install cmake
brew install webp
brew install jsoncpp

Linux (Debian)

  • Use webp to install cwebp and webpmux to your PATH.
  • Use apt-get to install all the dependencies.
sudo apt-get update
sudo apt-get install python
sudo apt-get install python-pip
sudo apt-get install cmake
sudo apt-get install libpng-dev
sudo apt-get install libjsoncpp-dev

Windows

  • Use python to install python and pip.
  • Use cmake to install cmake.
  • Use webp to install cwebp and webpmux to your PATH.
  • Use Mysys2 and MinGW-w64 to install external dependencies. Remember to add your MinGW-w64 folder(e.g. C:\msys64\mingw64\bin for 64bit and C:\msys64\mingw32\bin for 32bit) to your PATH.

Run Mysys2 shell(but not PowerShell) to install external dependencies.

pacman -Sy
pacman -S mingw-w64-x86_64-gcc
pacman -S mingw-w64-x86_64-make
pacman -S mingw-w64-x86_64-libpng
pacman -S mingw-w64-x86_64-jsoncpp

If you are using 32bit Windows, change all the command x86_64 to i686.

Additionally, current version mingw-w64-x86_64-make 4.2.1 has a dynamic link bug and can not run, if you are facing this issue, try pacman -S mingw-w64-x86_64-gettext to fix.

Compilation

macOS and Linux

For macOS and Linux user, run terminal shell.

In apng2webp_dependencies/ execute:

mkdir build
cd build
cmake ..
make
(sudo) make install

Windows

For Windows user, run PowerShell as Administrator user.

In apng2webp_dependencies/ execute:

mkdir build
cd build
cmake .. -G "MinGW Makefiles"
mingw32-make

Then add the output apngdisraw.exe and apng2webp_apngopt.exe to your PATH.

Installation

In project root folder execute:

(sudo) python setup.py install

Test

In project root folder execute:

(sudo) pip install pytest
python setup.py test

Thanks

APNG Disassembler
APNG Optimizer

License

Not all software within this project uses the same license. The following licenses/legal terms are used:

  • zlib license
  • GNU LGPL 2.1 for some older versions of some parts of the software
  • Public Domain (if explicitly stated. The .py scripts are public domain)
  • BSD 3-Clause where no other license applies (this readme)