{"id":29116679,"url":"https://github.com/HugoSmits86/nativewebp","last_synced_at":"2025-06-29T11:14:02.307Z","repository":{"id":270908858,"uuid":"908197385","full_name":"HugoSmits86/nativewebp","owner":"HugoSmits86","description":"Native webp encoder for Go","archived":false,"fork":false,"pushed_at":"2025-04-26T14:16:59.000Z","size":82,"stargazers_count":220,"open_issues_count":0,"forks_count":8,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-26T15:19:51.588Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HugoSmits86.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-12-25T12:18:02.000Z","updated_at":"2025-04-26T14:17:02.000Z","dependencies_parsed_at":"2025-01-04T00:23:57.909Z","dependency_job_id":"81b82e42-d524-4fbd-a30e-e123da5581f9","html_url":"https://github.com/HugoSmits86/nativewebp","commit_stats":null,"previous_names":["hugosmits86/nativewebp"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/HugoSmits86/nativewebp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HugoSmits86%2Fnativewebp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HugoSmits86%2Fnativewebp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HugoSmits86%2Fnativewebp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HugoSmits86%2Fnativewebp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HugoSmits86","download_url":"https://codeload.github.com/HugoSmits86/nativewebp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HugoSmits86%2Fnativewebp/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262581513,"owners_count":23331925,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-29T11:13:44.975Z","updated_at":"2025-06-29T11:14:02.280Z","avatar_url":"https://github.com/HugoSmits86.png","language":"Go","funding_links":[],"categories":["Images","图片"],"sub_categories":["Search and Analytic Databases","检索及分析资料库"],"readme":"[![Codecov Coverage](https://codecov.io/gh/HugoSmits86/nativewebp/branch/main/graph/badge.svg)](https://codecov.io/gh/HugoSmits86/nativewebp)\n[![Go Reference](https://pkg.go.dev/badge/github.com/HugoSmits86/nativewebp.svg)](https://pkg.go.dev/github.com/HugoSmits86/nativewebp)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n# Native WebP for Go\n\nThis is a native WebP encoder written entirely in Go, with **no dependencies on libwebp** or other external libraries. Designed for performance and efficiency, this encoder generates smaller files than the standard Go PNG encoder and is approximately **50% faster** in execution.\n\nCurrently, the encoder supports only WebP lossless images (VP8L).\n\n## Decoding Support\n\nWe provide WebP decoding through a wrapper around `golang.org/x/image/webp`, with an additional `DecodeIgnoreAlphaFlag` function to handle VP8X images where the alpha flag causes decoding issues.\n## Benchmark\n\nWe conducted a quick benchmark to showcase file size reduction and encoding performance. Using an image from Google’s WebP Lossless and Alpha Gallery, we compared the results of our nativewebp encoder with the standard PNG encoder. \u003cbr/\u003e\u003cbr/\u003e\nFor the PNG encoder, we applied the `png.BestCompression` setting to achieve the most competitive compression outcomes.\n\u003cbr/\u003e\u003cbr/\u003e\n\n\u003ctable align=\"center\"\u003e\n  \u003ctr\u003e\n    \u003cth\u003e\u003c/th\u003e\n    \u003cth\u003e\u003c/th\u003e\n    \u003cth\u003ePNG encoder\u003c/th\u003e\n    \u003cth\u003enativeWebP encoder\u003c/th\u003e\n    \u003cth\u003ereduction\u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd rowspan=\"2\" height=\"110px\"\u003e\u003cp align=\"center\"\u003e\u003cimg src=\"https://www.gstatic.com/webp/gallery3/1.png\" height=\"100px\"\u003e\u003c/p\u003e\u003c/td\u003e\n    \u003ctd\u003efile size\u003c/td\u003e\n    \u003ctd\u003e120 kb\u003c/td\u003e\n    \u003ctd\u003e96 kb\u003c/td\u003e\n    \u003ctd\u003e20% smaller\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eencoding time\u003c/td\u003e\n    \u003ctd\u003e42945049 ns/op\u003c/td\u003e\n    \u003ctd\u003e27716447 ns/op\u003c/td\u003e\n    \u003ctd\u003e35% faster\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd rowspan=\"2\" height=\"110px\"\u003e\u003cp align=\"center\"\u003e\u003cimg src=\"https://www.gstatic.com/webp/gallery3/2.png\" height=\"100px\"\u003e\u003c/p\u003e\u003c/td\u003e\n    \u003ctd\u003efile size\u003c/td\u003e\n    \u003ctd\u003e46 kb\u003c/td\u003e\n    \u003ctd\u003e36 kb\u003c/td\u003e\n    \u003ctd\u003e22% smaller\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eencoding time\u003c/td\u003e\n    \u003ctd\u003e98509399 ns/op\u003c/td\u003e\n    \u003ctd\u003e31461759 ns/op\u003c/td\u003e\n    \u003ctd\u003e68% faster\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd rowspan=\"2\" height=\"110px\"\u003e\u003cp align=\"center\"\u003e\u003cimg src=\"https://www.gstatic.com/webp/gallery3/3.png\" height=\"100px\"\u003e\u003c/p\u003e\u003c/td\u003e\n    \u003ctd\u003efile size\u003c/td\u003e\n    \u003ctd\u003e236 kb\u003c/td\u003e\n    \u003ctd\u003e194 kb\u003c/td\u003e\n    \u003ctd\u003e18% smaller\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eencoding time\u003c/td\u003e\n    \u003ctd\u003e178205535 ns/op\u003c/td\u003e\n    \u003ctd\u003e102454192 ns/op\u003c/td\u003e\n    \u003ctd\u003e43% faster\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd rowspan=\"2\" height=\"110px\"\u003e\u003cp align=\"center\"\u003e\u003cimg src=\"https://www.gstatic.com/webp/gallery3/4.png\" height=\"60px\"\u003e\u003c/p\u003e\u003c/td\u003e\n    \u003ctd\u003efile size\u003c/td\u003e\n    \u003ctd\u003e53 kb\u003c/td\u003e\n    \u003ctd\u003e41 kb\u003c/td\u003e\n    \u003ctd\u003e23% smaller\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eencoding time\u003c/td\u003e\n    \u003ctd\u003e29088555 ns/op\u003c/td\u003e\n    \u003ctd\u003e14959849 ns/op\u003c/td\u003e\n    \u003ctd\u003e49% faster\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd rowspan=\"2\" height=\"110px\"\u003e\u003cp align=\"center\"\u003e\u003cimg src=\"https://www.gstatic.com/webp/gallery3/5.png\" height=\"100px\"\u003e\u003c/p\u003e\u003c/td\u003e\n    \u003ctd\u003efile size\u003c/td\u003e\n    \u003ctd\u003e139 kb\u003c/td\u003e\n    \u003ctd\u003e123 kb\u003c/td\u003e\n    \u003ctd\u003e12% smaller\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eencoding time\u003c/td\u003e\n    \u003ctd\u003e63423995 ns/op\u003c/td\u003e\n    \u003ctd\u003e21717392 ns/op\u003c/td\u003e\n    \u003ctd\u003e66% faster\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\u003cp align=\"center\"\u003e\n\u003csub\u003eimage source: https://developers.google.com/speed/webp/gallery2\u003c/sub\u003e\n\u003c/p\u003e\n\n\n## Installation\n\nTo install the nativewebp package, use the following command:\n```Bash\ngo get github.com/HugoSmits86/nativewebp\n```\n## Usage\n\nHere’s a simple example of how to encode an image:\n```Go\nfile, err := os.Create(name)\nif err != nil {\n  log.Fatalf(\"Error creating file %s: %v\", name, err)\n}\ndefer file.Close()\n\nerr = nativewebp.Encode(file, img, nil)\nif err != nil {\n  log.Fatalf(\"Error encoding image to WebP: %v\", err)\n}\n```\n\nHere’s a simple example of how to encode an animation:\n```Go\nfile, err := os.Create(name)\nif err != nil {\n  log.Fatalf(\"Error creating file %s: %v\", name, err)\n}\ndefer file.Close()\n\nani := nativewebp.Animation{\n  Images: []image.Image{\n    frame1,\n    frame2,\n  },\n  Durations: []uint {\n    100,\n    100,\n  },\n  Disposals: []uint {\n    0,\n    0,\n  },\n  LoopCount: 0,\n  BackgroundColor: 0xffffffff,\n}\n\nerr = nativewebp.EncodeAll(file, \u0026ani, nil)\nif err != nil {\n  log.Fatalf(\"Error encoding WebP animation: %v\", err)\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHugoSmits86%2Fnativewebp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FHugoSmits86%2Fnativewebp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHugoSmits86%2Fnativewebp/lists"}