webp

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// The WebP header to look for.
	Header = "image/webp"
)
View Source
const Path = string(os.PathSeparator) + "webp"

Path defines the path where the executables reside.

Variables

This section is empty.

Functions

This section is empty.

Types

type Execer

type Execer interface {
	Install() error
	Accepts(ctx *gin.Context) bool
	File(g *gin.Context, path string, mime domain.Mime) ([]byte, error)
	Convert(path string, compression int)
}

Execer defines methods for WebP images to Convert and Obtain files from the file system.

type WebP

type WebP struct {
	// contains filtered or unexported fields
}

WebP

Defines the service for installing, converting, serving and determining if the browser can accept WebP images.

func New

func New(binPath string) *WebP

New

Creates a new WebP Execer.

func (*WebP) Accepts

func (w *WebP) Accepts(ctx *gin.Context) bool

Accepts

Determines if the browser can serve webp images by looking up the 'image/WebP' header.

func (*WebP) Convert

func (w *WebP) Convert(path string, compression int)

Convert

Converts an image to WebP based on compression and decoded image. Compression level is also set.

func (*WebP) File

func (w *WebP) File(ctx *gin.Context, path string, mime domain.Mime) ([]byte, error)

File

File first checks to see if the browser accepts WebP images and if the mime type is jpg or a png.

Returns the data file if found. Returns errors.INTERNAL if no file was found.

func (*WebP) Install

func (w *WebP) Install() error

Install

Installs the WebP executables to the path provided New. Returns errors.INTERNAL if an error occurred downloading.

Jump to

Keyboard shortcuts

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