README.md
1# libwebp-sys
2
3[bindgen](https://github.com/servo/rust-bindgen)'d FFI bindings to [libwebp](https://developers.google.com/speed/webp/docs/api).
4
5libwebp itself is built with cmake and linked statically.
6
7## Add manul ffi.rs
8
9add ffi.rs that generated by bindgen manually to avoid install llvm and clang in server
10
11## Usage
12
13Add the following to the Cargo.toml in your project:
14
15```
16[dependencies]
17libwebp-sys = "0.1"
18```
19
20and import useing extern crate:
21```
22extern crate libwebp_sys;
23```
24
25## Example
26Encode:
27```
28pub fn encode_webp(input_image: &[u8], width: u32, height: u32, quality: i32) -> Result<Vec<u8>> {
29 unsafe {
30 let mut out_buf = Box::into_raw(Box::new(0u8)) as *mut _;
31 let stride = width as i32 * 4;
32 let len = WebPEncodeRGBA(input_image.as_ptr(), width as i32, height as i32, stride, quality as f32, &mut out_buf as *mut _);
33 Ok(Vec::from_raw_parts(out_buf, len as usize, len as usize))
34 }
35}
36```