vipsgen provides automated generation of type-safe and idiomatic Go bindings for the libvips image processing library. Say goodbye to complex manual bindings and embrace an efficient approach that adapts to your installation. With comprehensive support and seamless integration, vipsgen is designed to enhance image processing in Go applications.
vipsgen is a powerful Go binding generator designed for the libvips image processing library, known for its speed and efficiency. This tool addresses the limitations of existing Go bindings that rely on manual code, which can often be incomplete, error-prone, and challenging to maintain as libvips evolves.
VipsSource bindings with io.ReadCloser for efficient streaming capabilities.To demonstrate the power of vipsgen, consider the following Go code snippet:
package main
import (
"fmt"
"log"
"net/http"
"github.com/cshum/vipsgen/vips"
)
func main() {
// Fetch an image via HTTP GET
resp, err := http.Get("https://raw.githubusercontent.com/cshum/imagor/master/testdata/gopher.png")
if err != nil {
log.Fatalf("Failed to fetch image: %v", err)
}
defer resp.Body.Close()
// Create a source from io.ReadCloser
source := vips.NewSource(resp.Body)
defer source.Close()
// Load a thumbnail image with specified options
image, err := vips.NewThumbnailSource(source, 800, &vips.ThumbnailSourceOptions{
Height: 1000,
FailOn: vips.FailOnError,
})
if err != nil {
log.Fatalf("Failed to load image: %v", err)
}
defer image.Close()
// Add a yellow border to the image
border := 10
if err := image.Embed(
border, border,
image.Width()+border*2,
image.Height()+border*2,
&vips.EmbedOptions{
Extend: vips.ExtendBackground,
Background: []float64{255, 255, 0, 255},
}); err != nil {
log.Fatalf("Failed to add border: %v", err)
}
fmt.Printf("Processed image: %dx%d\n", image.Width(), image.Height())
// Save the image as WebP with options
err = image.Webpsave("resized-gopher.webp", &vips.WebpsaveOptions{
Q: 85,
Effort: 4,
SmartSubsample: true,
})
if err != nil {
log.Fatalf("Failed to save image as WebP: %v", err)
}
fmt.Println("Successfully saved processed images")
}
For users interested in generating custom bindings, vipsgen requires libvips to be built with GObject introspection support. Users can easily generate bindings with:
vipsgen -out ./vips
The command line interface provides options to customize the output directory, templates, and debug settings. Use the following command to view available options:
Usage: vipsgen [options]
Options:
-out string Output directory (default "./out")
-templates string Template directory (uses embedded templates if not specified)
-extract Extract embedded templates and exit
-extract-dir string Directory to extract templates to (default "./templates")
-debug Enable debug json output
Contributions are welcomed to enhance the capabilities of vipsgen. This project presents a robust solution for developers looking to simplify image processing tasks in Go.
No comments yet.
Sign in to be the first to comment.