Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions docs/webp.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@

Scrimage provides support for webp through the `scrimage-webp` module. To use webp, add this module to your build.

This module uses the `dwebp` and `cwebp` binaries, created by Google. The `scrimage-webp` module comes with the linux_x64
binaries already included (see
required [copyright notice](https://github.com/sksamuel/scrimage/blob/master/scrimage-webp/src/main/resources/dist_webp_binaries/LICENSE))
.

If you don't wish to use the embedded binaries (eg, you need macos or windows binaries), then you
can [download other versions](https://developers.google.com/speed/webp) and place them on your classpath
at `/web_binaries/dwebp` or `/web_binaries/cwebp`.
> animated gif to animated webp is not currently supported in this module.

This module uses the `dwebp` and `cwebp` binaries, created by Google. The `scrimage-webp` module comes with the
linux_x64, window_x64, mac-10.15 binaries already included (see required [copyright notice](https://github.com/sksamuel/scrimage/blob/master/scrimage-webp/src/main/resources/dist_webp_binaries/LICENSE)).

If you don't wish to use the embedded binaries, then you can [download other versions](https://developers.google.com/speed/webp) and place them
on your classpath at `/web_binaries/{osName}/dwebp` or `/web_binaries/{osName}/cwebp`.

`{osName}` must be one of `window`, `linux`, `mac`. ie `/web_binaries/window/cwebp`.

or just place your binaries into `/web_binaries/dwebp` or `/web_binaries/cwebp`.
then scrimage will use `/web_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:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class CWebpHandler extends WebpHandler {
* https://storage.googleapis.com/downloads.webmproject.org/releases/webp/index.html
*/
private static void installCWebp() throws IOException {
installBinary(binary, "/webp_binaries/cwebp", "/dist_webp_binaries/cwebp");
installBinary(binary, getBinaryPath("cwebp"));
}

public byte[] convert(byte[] bytes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class DWebpHandler extends WebpHandler {
* https://storage.googleapis.com/downloads.webmproject.org/releases/webp/index.html
*/
private static void installDWebp() throws IOException {
installBinary(binary, "/webp_binaries/dwebp", "/dist_webp_binaries/dwebp");
installBinary(binary, getBinaryPath("dwebp"));
}

public byte[] convert(byte[] bytes) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ protected static void installBinary(Path output, String... sources) throws IOExc
throw new IOException("Could not locate webp binary at " + Arrays.toString(sources));
}

protected static String[] getBinaryPath(String binaryName) {
String os = "linux";

if(SystemUtils.IS_OS_WINDOWS) {
os = "window";
} else if(SystemUtils.IS_OS_MAC) {
os = "mac";
}

return new String[] {
"/webp_binaries/" + binaryName,
"/webp_binaries/" + os + "/" + binaryName,
"/dist_webp_binaries/" + os + "/" + binaryName,
};
}

private static boolean setExecutable(Path output) throws IOException {
try {
return new ProcessBuilder("chmod", "+x", output.toAbsolutePath().toString())
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ class WebpTest : FunSpec() {
}

test("dwebp should capture error on failure") {
val dwebpPath = WebpHandler.getBinaryPath("dwebp")[2]

shouldThrow<IOException> {
ImmutableImage.loader().fromResource("/dist_webp_binaries/dwebp")
ImmutableImage.loader().fromResource(dwebpPath)
}.message.shouldContain("BITSTREAM_ERROR")
}
}
Expand Down