Webp
Webp Support
Webp is a method of lossy and lossless compression created by Google.
Scrimage provides support for webp through the scrimage-webp module. To use webp, add this module to your build.
Note: Read the faq with regards to using this module inside a fat jar.
This module uses the dwebp, cwebp and gif2webp binaries, created by Google. The scrimage-webp module comes with the
linux_x64, linux_aarch64, window_x64, mac-x64 and mac-arm64 binaries already included (see required copyright notice).
If you don't wish to use the embedded binaries, then you can download other versions and use the system property "com.sksamuel.scrimage.webp.binary.dir" to configure the directory you placed the binaries:
java -Dcom.sksamuel.scrimage.webp.binary.dir="/tmp/webp" -jar myprogram.jar
/webp_binaries/{osName}/dwebp or /webp_binaries/{osName}/cwebp or
/webp_binaries/{osName}/gif2webp.
The directory set by the system property is always searched first.
{osName} must be one of window, linux, mac. ie /webp_binaries/window/cwebp.
or just place your binaries into /webp_binaries/dwebp or /webp_binaries/cwebp or /webp_binaries/gif2webp.
then scrimage will use /webp_binaries/{binary} regardless of the binaries which is in os specific directory.
Then you should be able to read webp files by using the ImageLoader as normal:
ImmutableImage.loader().fromFile(new File("someimage.webp"))
And write out images using the WebpWriter image writer, eg.
myimage.output(WebpWriter.MAX_LOSSLESS_COMPRESSION,"output.webp");
Animated Gif to Webp
The writer is configuration with options for compression quality, compression method, and lossless compression factor.
If want to change Animated Gif to webp, you should be able to read animated file by using by AnimatedGifReader as normal :
AnimatedGifReader.read(ImageSource.of(File("animated.gif"));
And write out AnimatedGif using the Gif2WebpWriter, eg.
animatedGif.bytes(Gif2WebpWriter.DEFAULT);
animatedGif.output(Gif2WebpWriter.DEFAULT, "output.webp");
The gif2webp writer is configuration with options for compression quality, compression method, and lossly compression factor.
animated webp to animated gif is not currently supported in this module.