diff --git a/.gitignore b/.gitignore index 348b7cd..805c680 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,4 @@ /src/test/resources/lossy1.webp /src/test/resources/lossy2.webp /src/test/resources/lossy3.webp -/build_libwebp.txt /target/ \ No newline at end of file diff --git a/readme.md b/readme.md index 097d229..ca7c71d 100644 --- a/readme.md +++ b/readme.md @@ -20,12 +20,19 @@ For more informations behind it and the required folder structure see the [readm The origin libwebp source includes a precompiled jar file which contains the native JNI bindings for libwebp library. It is referenced in central pom.xml file of sprd-webp project as 'com.google.webp|webp' -You must install this jar library into your local (or company) maven repository - mvn install:install-file -Dfile=libwebp.jar -DgroupId=com.google.webp -DartifactId=webp -Dversion=5.0.0 -Dpackaging=jar +Install this jar library into your local (or company) maven repository + + mvn install:install-file -Dfile=libwebp.jar -DgroupId=com.google.webp -DartifactId=webp -Dversion=5.0.0 -Dpackaging=jar # Testing and Examples You can find a simple example with different compression rates here: -src/test/java/net/sprd/image/webp/UsageExample.java + + src/test/java/net/sprd/image/webp/UsageExample.java + +# Travis-ci and releases + +[see](https://travis-ci.org/spreadshirt/sprd-webp) + diff --git a/src/test/java/net/sprd/image/webp/UsageExample.java b/src/test/java/net/sprd/image/webp/UsageExample.java index 220bd34..6b8d0f2 100644 --- a/src/test/java/net/sprd/image/webp/UsageExample.java +++ b/src/test/java/net/sprd/image/webp/UsageExample.java @@ -2,8 +2,11 @@ import com.google.webp.libwebp; import java.awt.image.BufferedImage; +import java.io.BufferedReader; import java.io.File; import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.lang.reflect.Method; import java.util.Iterator; @@ -37,10 +40,16 @@ public static void main(String[] args) throws IOException { String osName = System.getProperty("os.name"); String osArch = System.getProperty("os.arch"); + String osVersion = System.getProperty("os.version"); System.out.println("OS-NAME :" + osName); System.out.println("OS-ARCH :" + osArch); + System.out.println("OS-VERS :" + osVersion); + String distro = fromStream(Runtime.getRuntime().exec("lsb_release -i -s").getInputStream()); + System.out.println("OS-DISTRO :" + distro); + + String origFileName = "src/test/resources/test.png"; BufferedImage img = ImageIO.read(new File(origFileName)); @@ -66,9 +75,9 @@ private static File toWebp(String fileName, BufferedImage img, float quality) th ImageWriteParam param = writer.getDefaultWriteParam(); WebPWriteParam writeParam = (WebPWriteParam) param; if (quality < 0) { - writeParam.setCompressionType( WebPWriteParam.LOSSLESS); + writeParam.setCompressionType(WebPWriteParam.LOSSLESS); } else { - writeParam.setCompressionQuality( quality); + writeParam.setCompressionQuality(quality); } ImageOutputStream ios = ImageIO.createImageOutputStream(new File(fileName)); writer.setOutput(ios); @@ -77,4 +86,28 @@ private static File toWebp(String fileName, BufferedImage img, float quality) th return f; } + public static String fromStream(InputStream in) throws IOException { + try { + BufferedReader reader = new BufferedReader(new InputStreamReader(in)); + StringBuilder out = new StringBuilder(); + String newLine = System.getProperty("line.separator"); + String line; + while ((line = reader.readLine()) != null) { + out.append(line); + out.append(newLine); + } + return out.toString(); + } catch (Exception e) { + } finally { + if (in != null) { + try { + in.close(); + } catch (Exception e) { + } + + } + } + return ""; + } + }