Convert WebP to PNG using Java

Source: Internet
Author: User

WEBP is the image format of Google, Java class Library ImageIO is not supported in this format. For now, in addition to online conversions and tools, the third-party class library conversion WEBP format is roughly:

1.linux:google LIBWEBP is both a class library and can be invoked at the command line

2.python:python Image Library (PIL) and its branches Https://pypi.python.org/pypi/PIL I don't know much.

3.java:luciad/webp-imageio HTTPS://BITBUCKET.ORG/LUCIAD/WEBP-IMAGEIO/SRC confirmed available (Linux environment)


This article describes the third method:

Under the Linux environment. Put Google libwebp-0.4.0 in the luciad-webp-imageio-2962dd563583 root folder. Install CMake and run CMake within the root folder above. command, run the make command under the above root folder when CMake is finished. Make completes the. jar and. So files, respectively, under the Java folder and the C folder.

Import the. jar into your Java project path and put the. so file to the system Java path. You can read and write WEBP format files using ImageIO in your Java project at this point.


Description

Operating Environment: Ubuntu

Language: Java

Example: WEBP to PNG


Steps:

One: Download the following three packages

1.CMake installation package: Cmake-3.1.0-rc2-linux-i386.tar

2.Google WEBP Dependent Library: libwebp-0.4.0.tar.gz Original address:

HL=ZH-CN ">HTTPS://DEVELOPERS.GOOGLE.COM/SPEED/WEBP/DOWNLOAD?HL=ZH-CN

3.luciad/webp-imageioproject:luciad-webp-imageio-2962dd563583.zip Original Address: HTTPS://BITBUCKET.ORG/LUCIAD/WEBP-IMAGEIO/SRC


Consider the above resources need FQ download. More slowly. I have transferred three files to csdn,0 for download.


Address: http://download.csdn.net/detail/geeklei/8161731


Two: Compile to get Webp-imageio.jar and libwebp-imageio.so

1. Unzip the luciad-webp-imageio-2962dd563583.zip.

2. Extract the libwebp-0.4.0.tar.gz to the luciad-webp-imageio-2962dd563583 root folder.

3. Unzip the Cmake-3.1.0-rc2-linux-i386.tar.

CMake decompression is available. Of course, you can also download the installation from the image source by using the command itself.

4. Under the luciad-webp-imageio-2962dd563583 root folder, run CMake under the premise that CMake is available. Command. Pay attention to CMake and. There is a space between

5.cmake end, see the Makefile file, run the make command under the luciad-webp-imageio-2962dd563583 root folder.

At the end of 6.make, you can see the. jar and. So in the Java and C folders under the luciad-webp-imageio-2962dd563583 root folder.


Three:

1. Import the Webp-imageio.jar into your own Java project in Eclipse.

2. Place the libwebp-imageio.so in the system Java path.

Ability to reuse System.out.println (System.getproperty ("Java.library.path")) in the project, and the statement to print out the Java path. Avoid omissions. There are multiple printed Java paths, 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/640a.png"); System.out.println (System.getproperty ("Java.library.path")); try {BufferedImage im = Imageio.read (file1); Imageio.write (IM, "png", file2);} catch (IOException e) {e.printstacktrace ();}


Thanks to the efforts of Luciad/webp-imageio project author Luciad and the selfless help of my questions.


--------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------

It was found this morning that a compiled package was uploaded to the project.

I didn't test it either. Just share the bag, too.

Original address: Https://bitbucket.org/luciad/webp-imageio/downloads

CSDN Address: http://download.csdn.net/detail/geeklei/8163329


There are. jar. So. dll

Covers Linux 32/64 version numbers such as Windows 32/64

Convert WebP to PNG using Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.