Skip to content
This repository has been archived by the owner on Aug 6, 2021. It is now read-only.

Commit

Permalink
update readme, prepare release
Browse files Browse the repository at this point in the history
  • Loading branch information
ran committed Apr 5, 2016
1 parent b7de570 commit 6ee9c6d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
/src/test/resources/lossy1.webp
/src/test/resources/lossy2.webp
/src/test/resources/lossy3.webp
/build_libwebp.txt
/target/
13 changes: 10 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)


37 changes: 35 additions & 2 deletions src/test/java/net/sprd/image/webp/UsageExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));

Expand All @@ -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);
Expand All @@ -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 "";
}

}

0 comments on commit 6ee9c6d

Please sign in to comment.