Skip to content

Commit f4556c7

Browse files
authored
Initial commit
1 parent a39de2c commit f4556c7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1855
-1
lines changed

README.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,51 @@
11
# defold-webp
2-
Defold native extension for WebP images
2+
3+
A Defold extension for using WebP images. Uses [libwebp-1.6.0](https://github.com/webmproject/libwebp).
4+
5+
## Installation
6+
7+
This asset can be added as a [library dependency](https://defold.com/manuals/libraries/#setting-up-library-dependencies) in your project:
8+
9+
* Use a specific version for development and release to avoid breaking changes: https://github.com/HalfstarDev/defold-webp/releases
10+
* Use the latest version only while evaluating and testing the asset: https://github.com/HalfstarDev/defold-webp/archive/master.zip
11+
12+
For Android, the minimum SDK version is 21.
13+
14+
## Usage
15+
16+
#### webp.decode(image [, options])
17+
18+
Decode a WebP image into an image buffer. Use optional Lua table with [WebPDecoderOptions](https://developers.google.com/speed/webp/docs/api#advanced_decoding_api) as keys. Returns buffer, width, and height.
19+
20+
```
21+
local buf, w, h = webp.decode(sys.load_resource("/assets/image_1.webp"))
22+
resource.set_texture(go.get("#sprite", "texture0"), {
23+
width = w,
24+
height = h,
25+
type = resource.TEXTURE_TYPE_2D,
26+
format = resource.TEXTURE_FORMAT_RGBA,
27+
num_mip_maps = 1
28+
}, buf)
29+
```
30+
31+
#### webp.encode(buffer, width, height [, options])
32+
33+
Encode a image buffer into a WebP image. Use optional Lua table with [WebPConfig](https://developers.google.com/speed/webp/docs/api#advanced_encoding_api) fields as keys. Returns string with WebP image.
34+
35+
```
36+
local buf, w, h = webp.decode(image)
37+
local webp_image = webp.encode(buf, w, h, {quality = 50})
38+
local f = io.open("out.webp", "wb")
39+
if f then
40+
f:write(webp_image)
41+
f:close()
42+
end
43+
```
44+
45+
#### webp.get_info(image)
46+
47+
Get information about a WebP image. Returns table with following fields: width, height, has_alpha, has_animation, lossy.
48+
```
49+
local info = webp.get_info(image)
50+
print(info.width, info.height)
51+
```

assets/cat_lossless.webp

226 KB
Loading

assets/cat_low.webp

45.9 KB
Loading

assets/image_1.webp

193 KB
Loading

assets/image_2.webp

453 KB
Loading

assets/image_3.webp

142 KB
Loading

example/atlases/1.atlas

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
images {
2+
image: "/example/atlases/1.png"
3+
}

example/atlases/1.png

115 Bytes
Loading

example/atlases/2.atlas

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
images {
2+
image: "/example/atlases/2.png"
3+
}

example/atlases/2.png

115 Bytes
Loading

0 commit comments

Comments
 (0)