Add WebP encoding support
Uses github.com/gen2brain/webp - a CGO-free library that uses WASM via wazero runtime for encoding. WebP decoding was already supported. - Add gen2brain/webp dependency for encoding - Implement WebP encoding in processor.go - Add FormatWebP to SupportedOutputFormats - Re-enable WebP option in generator form dropdown - Mark WebP encoding as complete in TODO.md
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"io"
|
||||
|
||||
"github.com/disintegration/imaging"
|
||||
gowebp "github.com/gen2brain/webp"
|
||||
"golang.org/x/image/webp"
|
||||
)
|
||||
|
||||
@@ -122,6 +123,7 @@ func (p *ImageProcessor) SupportedOutputFormats() []ImageFormat {
|
||||
FormatJPEG,
|
||||
FormatPNG,
|
||||
FormatGIF,
|
||||
FormatWebP,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,7 +229,14 @@ func (p *ImageProcessor) encode(img image.Image, format ImageFormat, quality int
|
||||
}
|
||||
|
||||
case FormatWebP:
|
||||
return nil, fmt.Errorf("%w: WebP encoding not supported", ErrUnsupportedOutputFormat)
|
||||
options := gowebp.Options{
|
||||
Lossless: false,
|
||||
Quality: quality,
|
||||
}
|
||||
err := gowebp.Encode(&buf, img, options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
case FormatAVIF:
|
||||
return nil, fmt.Errorf("%w: AVIF encoding not supported", ErrUnsupportedOutputFormat)
|
||||
|
||||
@@ -108,6 +108,7 @@
|
||||
<option value="orig" {{if eq .FormFormat "orig"}}selected{{end}}>Original</option>
|
||||
<option value="jpeg" {{if eq .FormFormat "jpeg"}}selected{{end}}>JPEG</option>
|
||||
<option value="png" {{if eq .FormFormat "png"}}selected{{end}}>PNG</option>
|
||||
<option value="webp" {{if eq .FormFormat "webp"}}selected{{end}}>WebP</option>
|
||||
<option value="gif" {{if eq .FormFormat "gif"}}selected{{end}}>GIF</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user