webp

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 28, 2024 License: MIT Imports: 5 Imported by: 0

README

GO WebP

This is a simple library Go to convert images to WebP format using the libwebp library.

Development Requirements

  • Go 1.22
  • libwebp-dev

Before running the project, you need to install the libwebp-dev package. You can install it by running the following command:

# Ubuntu
sudo apt-get install libwebp-dev

Installation

To install the library, you need to run the following command:

go get github.com/ryanbekhen/go-webp

Usage

To use the library, you need to run the following command:

package main

import (
	"github.com/ryanbekhen/go-webp"
	"image"
	_ "image/jpeg"
	_ "image/png"
	"os"
)

func main() {
	input := "img.png"
	output := "img.webp"

	// Open the input image file.
	imgFile, err := os.Open(input)
	if err != nil {
		panic(err)
	}
	defer imgFile.Close()

	// Decode the input image file.
	img, _, err := image.Decode(imgFile)
	if err != nil {
		panic(err)
	}

	// Create the output image file.
	outFile, err := os.Create(output)
	if err != nil {
		panic(err)
	}
	defer outFile.Close()

	// Encode the input image file.
	err = webp.Encode(img, 75, outFile)
	if err != nil {
		panic(err)
	}
}

Note: The quality parameter is a number between 0 and 100. import _ "image/jpeg" and import _ "image/png" are required to decode the input image file.

Contributing

Contributions are welcome! For feature requests and bug reports please submit an issue.

License

This project is licensed under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(img image.Image, quality float32, dest io.Writer) error

Encode encodes the input image in the WebP format with the specified quality and writes it to the given destination writer. The function converts the image into a byte slice and calls a C function to perform the encoding. The resulting encoded data is written to the destination writer. If there are any errors during the encoding or writing process, an error is returned. Note: The C function is not included in this code snippet, it must be implemented separately. Example usage:

err := webp.Encode(img, 75, w)
if err != nil {
    log.Fatal(err)
}

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL