WebP is Google's image format, and the Java class library imageio does not support this format. Currently, in addition to online conversion and tools, the webp formats of third-party library conversion are roughly:
: Google libwebp is both a class library and can be called on the command line
: Python Image Library (PIL) and its branches /pypi/PIL Don't know much
: luciad/webp-imageio /luciad/webp-imageio/src Confirmed to be available (in linux environment)
This article describes the third method:
In the Linux environment, put Google libwebp-0.4.0 into the luciad-webp-imageio-2962dd563583 root directory, install CMake, and execute the cmake . command in the above root directory. After cmake is completed, execute the make command in the above root directory. Complete make will generate .jar and .so files in the java directory and the c directory respectively. Import .jar into your own java project path and place the .so file in the system java path. At this time, use imageio in the java project to read and write webp format files.
illustrate:
Operating environment: ubuntu
Language: java
Example: webp to png
step:
1: Download the following three file packages
Installation package: cmake-3.1.
webp dependency library: libwebp-0.4. Original address: /speed/webp/download?hl=zh-cN
/webp-imageio project: Original address: /luciad/webp-imageio/src
Considering that the above resources need to be downloaded through the wall, it is relatively slow. I have passed three files to csdn and downloaded at 0 points.
Address: /detail/geeklei/8161731
Two: Compile to get and
1. Unzip.
2. Unzip libwebp-0.4. to luciad-webp-imageio-2962dd563583 root directory.
3. Unzip cmake-3.1. Cmake is ready to use, of course you can also download and install it from the mirror source by yourself using the command.
4. On the premise of ensuring that cmake is available, execute the cmake . command in the luciad-webp-imageio-2962dd563583 root directory. Note that there is a space between cmake and .
At the end, I saw the makefile file and execute the make command in the luciad-webp-imageio-2962dd563583 root directory.
End, you can see .jar and .so in the java and c folders in the root directory of luciad-webp-imageio-2962dd563583.
three:
1. Import it into your own java project in eclipse.
2. Place it in the system java path. You can use the (("")); statement in the project to print out the java path to avoid omissions. There are multiple java paths printed, some of which are repeated.
3. Use ImageIO in the project to read and write webp format files.
Code:
File file1= new File("/home/geeklei/Desktop/640_tp.webp"); File file2= new File("/home/geeklei/Desktop/"); (("")); try { BufferedImage im = (file1); (im, "png", file2); } catch (IOException e) { (); }
Thanks to Luciad/webp-imageio project author Luciad for his efforts and his selfless help in my question.
This morning I found someone uploaded the compiled package to the project. . I didn't test it, but I'll share the package. Original address: /luciad/webp-imageio/downloads
csdn address: /detail/geeklei/8163329
There is .jar .so .dll inside
Covering linux 32/64 windows 32/64 and other versions