Issue 171 in webp: i try to convert JPG to WEBP by webp-imageio ,But fail . Can someone help me?

190 views
Skip to first unread message

we...@googlecode.com

unread,
Sep 7, 2013, 5:40:26 AM9/7/13
to webp-d...@webmproject.org
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 171 by caoyaoju...@gmail.com: i try to convert JPG to WEBP by
webp-imageio ,But fail . Can someone help me?
http://code.google.com/p/webp/issues/detail?id=171

I follow the following operations
first:

https://bitbucket.org/luciad/webp-imageio by this i get jar
webp-imageio.jar and webp-imageio.so

second :

i create a test like this:

public class TestWebp {

private static boolean NATIVE_LIBRARY_LOADED = false;

static synchronized void loadNativeLibrary() {
if (!NATIVE_LIBRARY_LOADED) {
NATIVE_LIBRARY_LOADED = true;
System.loadLibrary("webp-imageio");
}
}

static {
loadNativeLibrary();
}

public static void main(String[] args) throws Exception {
// read image file
String f = "/home/caoyaojun/Pictures/1353735742546_original.jpg";
File file = new File(f);
FileInputStream fileInputStream = new FileInputStream(file);
byte[] orginabyte = new byte[200000000];
fileInputStream.read(orginabyte);
BufferedImage image = getImage(orginabyte);
// compression
byte[] optimizedData = optimize(0.8F, "webp", image);
// write image file
FileOutputStream out = new
FileOutputStream("/home/caoyaojun/Pictures/test.webp");
out.write(optimizedData);
out.flush();
out.close();
}

/**
* get image
*
* @param data
* @return
* @throws IOException
*/
private static BufferedImage getImage(byte[] data) throws IOException {
ByteArrayInputStream byteArrayInputStream = new
ByteArrayInputStream(data);
BufferedImage image = null;
try {
image = ImageIO.read(byteArrayInputStream);
return image;
} catch (IOException e) {
throw new IOException("read image exception!", e);
} finally {
try {
byteArrayInputStream.close();
} catch (IOException e) {
}
}
}

private static byte[] optimize(Float compressionQuality, String
extension, BufferedImage image) throws Exception {
// get writer
ImageWriter imgWrier =
ImageIO.getImageWritersByFormatName(extension).next();
ImageWriteParam imgWriteParams = new WebPWriteParam(null);
imgWriteParams.setCompressionType("Lossy");
// 0~1
imgWriteParams.setCompressionQuality(compressionQuality);
ByteArrayOutputStream byteArrayOutputStream = new
ByteArrayOutputStream();
try {
ImageOutputStream imageOutputStream =
ImageIO.createImageOutputStream(byteArrayOutputStream);
imgWrier.setOutput(imageOutputStream);
imgWrier.write(null, new IIOImage(image, null, null),
imgWriteParams);
int length = (int) imageOutputStream.length();
byte[] resultDate = new byte[length];
imageOutputStream.read(resultDate, 0, length);
return resultDate;
} catch (Exception e) {
throw new Exception(e);
} finally {
try {
byteArrayOutputStream.close();
} catch (IOException e) {
}
}
}
}


i can get file, and not empty. but i can not open with chrome;
the operating system is ubuntu 13.04


can somebody helpe me?

--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

we...@googlecode.com

unread,
Jan 29, 2014, 4:22:08 PM1/29/14
to webp-d...@webmproject.org

Comment #1 on issue 171 by pascal.m...@gmail.com: i try to convert JPG to
WEBP by webp-imageio ,But fail . Can someone help me?
http://code.google.com/p/webp/issues/detail?id=171

can you open it with 'vwebp' tool? Does it display correctly?

What does 'webpmux -info' or 'dwebp' say about this file? Is it a valid one?

we...@googlecode.com

unread,
Aug 21, 2014, 7:17:31 AM8/21/14
to webp-d...@webmproject.org

Comment #2 on issue 171 by macma...@gmail.com: i try to convert JPG to WEBP
by webp-imageio ,But fail . Can someone help me?
http://code.google.com/p/webp/issues/detail?id=171

i meet the same problem, the output file's header is not like a webp image.
Reply all
Reply to author
Forward
0 new messages