EN | RU
These scripts allows you to convert *.webp
or *.webm
images to *.gif
(with animation and transparency preserved).
Solution based on:
I suggest you to use Docker container, but you can still install all required packages and execute scripts in your system too (see below).
Some example files was taken from ticket on ffmpeg
(when attempt to convert webp
images with ANIM
and ANMF
blocks inside them).
- Docker and Docker Compose.
The Docker container was based on Debian, so instructions below will be for Debian too.
See ./Dockerfile
for more info.
-
Install required packages:
sudo apt update && apt install -y \ gcc make autoconf automake libtool \ libpng-dev libjpeg-dev libgif-dev libwebp-dev libtiff-dev libsdl2-dev \ git \ ffmpeg \ gifsicle
-
Clone
libwebp
repository and addanim_dump
support to build configuration:git clone https://chromium.googlesource.com/webm/libwebp && \ cd libwebp && \ echo "bin_PROGRAMS += anim_dump" >> ./examples/Makefile.am
-
Configure build files:
./autogen.sh && \ ./configure
-
Install:
make && \ sudo make install && \ echo "/usr/local/lib" | sudo tee -a /etc/ld.so.conf && \ sudo ldconfig
-
Check installation:
webpinfo -version && \ anim_dump -version
-
Remove cloned repository:
cd .. && \ rm -rf ./libwebp
For both usages you need to:
-
Clone the repository:
git clone https://github.com/Nikolai2038/webp-to-gif.git && \ cd webp-to-gif
-
Put your
.webp
or.webm
images insidedata
folder (you can create subfolders - all will be ignored in GIT, exceptexamples
directory)
-
Pull the image from DockerHub or build it yourself:
-
Pull:
docker-compose pull
-
Build it yourself (see
./Dockerfile
on how it will be built):docker-compose build
-
-
Start the container in the background (the repository root folder will be mounted):
docker-compose up --detach
-
Now you can execute scripts (the paths to images must be relative and be inside repository folder, since they are accessed from the container):
-
Convert specific
webp
file togif
:./convert_one.sh <file path> [0|1 - enable transparency, default is 1] [0|1|2 - compression level, default is 1]
-
Convert all
webp
files in a specific directory togif
:./convert_all_in_dir.sh <directory path> [0|1 - enable transparency, default is 1] [0|1|2 - compression level, default is 1]
-
Convert all
webp
example files (inside./data/examples
) togif
:./test.sh [0|1 - enable transparency, default is 1] [0|1|2 - compression level, default is 1]
-
Remove ALL
gif
files inside./data
directory (recursively):./clear.sh
You can also execute raw command, but remember to use scripts inside
./scripts
directory. For example:docker-compose exec webp-to-gif bash -c './scripts/convert_one.sh ./data/examples/01_girl.webp 0 1'
-
-
To stop and remove container, use:
docker-compose down
Just use scripts in ./scripts
directory, not in repository's root. The arguments are the same.
-
There are several example files in the
./data/examples
directory, for example,01_girl.webp
. -
Let's generate
gif
with transparency enabled:./convert_one.sh ./data/examples/01_girl.webp 1 1
After some execution the
./data/examples/01_girl.gif
image will be generated: -
Rename
01_girl.gif
to01_girl_transparency.gif
so script won't override it later. -
Let's run script again, but with transparency disabled now:
./convert_one.sh ./data/examples/01_girl.webp 0 1
New
01_girl.gif
image will be generated:As we can see, all transparency pixels are now black!
-
Rename result image to
01_girl_no_transparency.gif
.
Feel free to contribute via pull requests or issues!