1
0
mirror of https://github.com/coalaura/ffwebp.git synced 2025-09-08 05:49:54 +00:00

heif/heic

This commit is contained in:
Laura
2025-08-12 15:45:19 +02:00
parent 90aca0c3e9
commit 9569dfb8c1
6 changed files with 92 additions and 1 deletions

View File

@@ -6,7 +6,7 @@ FFWebP is a small, single-binary CLI for converting images between formats, thin
- Single binary: no external tools required - Single binary: no external tools required
- Auto-detects input codec and infers output from the file extension - Auto-detects input codec and infers output from the file extension
- Supports AVIF, BMP, Farbfeld, GIF, ICO, JPEG, JPEG XL, PCX, PNG, PNM (PBM/PGM/PPM/PAM), PSD (decode-only), QOI, SVG (decode-only), TGA, TIFF, WebP and XBM - Supports AVIF, BMP, Farbfeld, GIF, HEIF/HEIC, ICO/CUR, JPEG, JPEG XL, PCX, PNG, PNM (PBM/PGM/PPM/PAM), PSD (decode-only), QOI, SVG (decode-only), TGA, TIFF, WebP and XBM
- Lossy or lossless output with configurable quality - Lossy or lossless output with configurable quality
- Thumbnail generation via Lanczos3 resampling - Thumbnail generation via Lanczos3 resampling
- Per-codec flags for fine-grained control (see `ffwebp --help`) - Per-codec flags for fine-grained control (see `ffwebp --help`)

1
go.mod
View File

@@ -8,6 +8,7 @@ require (
github.com/anthonynsimon/bild v0.14.0 github.com/anthonynsimon/bild v0.14.0
github.com/ftrvxmtrx/tga v0.0.0-20150524081124-bd8e8d5be13a github.com/ftrvxmtrx/tga v0.0.0-20150524081124-bd8e8d5be13a
github.com/gen2brain/avif v0.4.4 github.com/gen2brain/avif v0.4.4
github.com/gen2brain/heic v0.4.5
github.com/gen2brain/jpegxl v0.4.5 github.com/gen2brain/jpegxl v0.4.5
github.com/gen2brain/webp v0.5.5 github.com/gen2brain/webp v0.5.5
github.com/hullerob/go.farbfeld v0.0.0-20181222022525-3661193c725f github.com/hullerob/go.farbfeld v0.0.0-20181222022525-3661193c725f

2
go.sum
View File

@@ -8,6 +8,8 @@ github.com/ftrvxmtrx/tga v0.0.0-20150524081124-bd8e8d5be13a h1:eSqaRmdlZ9JsJ7JuW
github.com/ftrvxmtrx/tga v0.0.0-20150524081124-bd8e8d5be13a/go.mod h1:US5WvgEHtG+BvWNNs6gk937h0QL2g2x+r7RH8m3g80Y= github.com/ftrvxmtrx/tga v0.0.0-20150524081124-bd8e8d5be13a/go.mod h1:US5WvgEHtG+BvWNNs6gk937h0QL2g2x+r7RH8m3g80Y=
github.com/gen2brain/avif v0.4.4 h1:Ga/ss7qcWWQm2bxFpnjYjhJsNfZrWs5RsyklgFjKRSE= github.com/gen2brain/avif v0.4.4 h1:Ga/ss7qcWWQm2bxFpnjYjhJsNfZrWs5RsyklgFjKRSE=
github.com/gen2brain/avif v0.4.4/go.mod h1:/XCaJcjZraQwKVhpu9aEd9aLOssYOawLvhMBtmHVGqk= github.com/gen2brain/avif v0.4.4/go.mod h1:/XCaJcjZraQwKVhpu9aEd9aLOssYOawLvhMBtmHVGqk=
github.com/gen2brain/heic v0.4.5 h1:Cq3hPu6wwlTJNv2t48ro3oWje54h82Q5pALeCBNgaSk=
github.com/gen2brain/heic v0.4.5/go.mod h1:ECnpqbqLu0qSje4KSNWUUDK47UPXPzl80T27GWGEL5I=
github.com/gen2brain/jpegxl v0.4.5 h1:TWpVEn5xkIfsswzkjHBArd0Cc9AE0tbjBSoa0jDsrbo= github.com/gen2brain/jpegxl v0.4.5 h1:TWpVEn5xkIfsswzkjHBArd0Cc9AE0tbjBSoa0jDsrbo=
github.com/gen2brain/jpegxl v0.4.5/go.mod h1:4kWYJ18xCEuO2vzocYdGpeqNJ990/Gjy3uLMg5TBN6I= github.com/gen2brain/jpegxl v0.4.5/go.mod h1:4kWYJ18xCEuO2vzocYdGpeqNJ990/Gjy3uLMg5TBN6I=
github.com/gen2brain/webp v0.5.5 h1:MvQR75yIPU/9nSqYT5h13k4URaJK3gf9tgz/ksRbyEg= github.com/gen2brain/webp v0.5.5 h1:MvQR75yIPU/9nSqYT5h13k4URaJK3gf9tgz/ksRbyEg=

View File

@@ -0,0 +1,8 @@
//go:build heif || full
// +build heif full
package builtins
import (
_ "github.com/coalaura/ffwebp/internal/codec/heif"
)

View File

@@ -0,0 +1,80 @@
package heif
import (
"bytes"
"fmt"
"image"
"io"
"github.com/gen2brain/heic"
"github.com/coalaura/ffwebp/internal/codec"
"github.com/coalaura/ffwebp/internal/opts"
"github.com/urfave/cli/v3"
)
func init() {
codec.Register(impl{})
}
type impl struct{}
func (impl) String() string {
return "heif"
}
func (impl) Extensions() []string {
return []string{"heic", "heif"}
}
func (impl) CanEncode() bool {
return false
}
func (impl) Flags(flags []cli.Flag) []cli.Flag {
return flags
}
func (impl) Sniff(reader io.ReaderAt) (int, []byte, error) {
buf := make([]byte, 32)
n, err := reader.ReadAt(buf, 0)
if err != nil && err != io.EOF {
return 0, nil, err
}
buf = buf[:n]
if len(buf) < 12 {
return 0, nil, nil
}
if !bytes.Equal(buf[4:8], []byte("ftyp")) {
return 0, nil, nil
}
brands := [][]byte{
[]byte("heic"),
[]byte("heix"),
[]byte("hevc"),
[]byte("hevx"),
[]byte("mif1"),
[]byte("msf1"),
}
for _, b := range brands {
if bytes.Contains(buf[8:], b) {
return 90, buf[:n], nil
}
}
return 0, nil, nil
}
func (impl) Decode(reader io.Reader) (image.Image, error) {
return heic.Decode(reader)
}
func (impl) Encode(writer io.Writer, img image.Image, options opts.Common) error {
return fmt.Errorf("heif: encoding not supported")
}

BIN
test/image.cur Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 176 KiB