diff --git a/docs/webp.md b/docs/webp.md index a41bf4f4..30d66631 100644 --- a/docs/webp.md +++ b/docs/webp.md @@ -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: diff --git a/scrimage-webp/src/main/java/com/sksamuel/scrimage/webp/CWebpHandler.java b/scrimage-webp/src/main/java/com/sksamuel/scrimage/webp/CWebpHandler.java index d9048184..4a0a8fa8 100644 --- a/scrimage-webp/src/main/java/com/sksamuel/scrimage/webp/CWebpHandler.java +++ b/scrimage-webp/src/main/java/com/sksamuel/scrimage/webp/CWebpHandler.java @@ -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, diff --git a/scrimage-webp/src/main/java/com/sksamuel/scrimage/webp/DWebpHandler.java b/scrimage-webp/src/main/java/com/sksamuel/scrimage/webp/DWebpHandler.java index f8edb7a6..bb0f50e3 100644 --- a/scrimage-webp/src/main/java/com/sksamuel/scrimage/webp/DWebpHandler.java +++ b/scrimage-webp/src/main/java/com/sksamuel/scrimage/webp/DWebpHandler.java @@ -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 { diff --git a/scrimage-webp/src/main/java/com/sksamuel/scrimage/webp/WebpHandler.java b/scrimage-webp/src/main/java/com/sksamuel/scrimage/webp/WebpHandler.java index 125cb067..ab751f36 100644 --- a/scrimage-webp/src/main/java/com/sksamuel/scrimage/webp/WebpHandler.java +++ b/scrimage-webp/src/main/java/com/sksamuel/scrimage/webp/WebpHandler.java @@ -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()) diff --git a/scrimage-webp/src/main/resources/dist_webp_binaries/cwebp b/scrimage-webp/src/main/resources/dist_webp_binaries/cwebp deleted file mode 100755 index d0689916..00000000 Binary files a/scrimage-webp/src/main/resources/dist_webp_binaries/cwebp and /dev/null differ diff --git a/scrimage-webp/src/main/resources/dist_webp_binaries/dwebp b/scrimage-webp/src/main/resources/dist_webp_binaries/dwebp deleted file mode 100755 index c4ec64dd..00000000 Binary files a/scrimage-webp/src/main/resources/dist_webp_binaries/dwebp and /dev/null differ diff --git a/scrimage-webp/src/main/resources/dist_webp_binaries/linux/cwebp b/scrimage-webp/src/main/resources/dist_webp_binaries/linux/cwebp new file mode 100644 index 00000000..bfabe848 Binary files /dev/null and b/scrimage-webp/src/main/resources/dist_webp_binaries/linux/cwebp differ diff --git a/scrimage-webp/src/main/resources/dist_webp_binaries/linux/dwebp b/scrimage-webp/src/main/resources/dist_webp_binaries/linux/dwebp new file mode 100644 index 00000000..dee658e3 Binary files /dev/null and b/scrimage-webp/src/main/resources/dist_webp_binaries/linux/dwebp differ diff --git a/scrimage-webp/src/main/resources/dist_webp_binaries/mac/cwebp b/scrimage-webp/src/main/resources/dist_webp_binaries/mac/cwebp new file mode 100644 index 00000000..eeb2c4c3 Binary files /dev/null and b/scrimage-webp/src/main/resources/dist_webp_binaries/mac/cwebp differ diff --git a/scrimage-webp/src/main/resources/dist_webp_binaries/mac/dwebp b/scrimage-webp/src/main/resources/dist_webp_binaries/mac/dwebp new file mode 100644 index 00000000..f6f0e8ef Binary files /dev/null and b/scrimage-webp/src/main/resources/dist_webp_binaries/mac/dwebp differ diff --git a/scrimage-webp/src/main/resources/dist_webp_binaries/window/cwebp b/scrimage-webp/src/main/resources/dist_webp_binaries/window/cwebp new file mode 100644 index 00000000..477b337a Binary files /dev/null and b/scrimage-webp/src/main/resources/dist_webp_binaries/window/cwebp differ diff --git a/scrimage-webp/src/main/resources/dist_webp_binaries/window/dwebp b/scrimage-webp/src/main/resources/dist_webp_binaries/window/dwebp new file mode 100644 index 00000000..cab5e57d Binary files /dev/null and b/scrimage-webp/src/main/resources/dist_webp_binaries/window/dwebp differ diff --git a/scrimage-webp/src/test/kotlin/com/sksamuel/scrimage/webp/WebpTest.kt b/scrimage-webp/src/test/kotlin/com/sksamuel/scrimage/webp/WebpTest.kt index 7eb06c1d..40543b22 100644 --- a/scrimage-webp/src/test/kotlin/com/sksamuel/scrimage/webp/WebpTest.kt +++ b/scrimage-webp/src/test/kotlin/com/sksamuel/scrimage/webp/WebpTest.kt @@ -24,8 +24,10 @@ class WebpTest : FunSpec() { } test("dwebp should capture error on failure") { + val dwebpPath = WebpHandler.getBinaryPath("dwebp")[2] + shouldThrow { - ImmutableImage.loader().fromResource("/dist_webp_binaries/dwebp") + ImmutableImage.loader().fromResource(dwebpPath) }.message.shouldContain("BITSTREAM_ERROR") } }