mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-13 09:20:29 -07:00
Adds AVIF support
* This adds a new type AVIF to the supported type list if libvips >= 8.9.0 * Calls libheif through libvips with the AV1 compression set to save AVIF images.
This commit is contained in:
parent
4f683f98d8
commit
83c14048e0
9 changed files with 86 additions and 9 deletions
18
type_test.go
18
type_test.go
|
|
@ -22,6 +22,7 @@ func TestDeterminateImageType(t *testing.T) {
|
|||
{"test.heic", HEIF},
|
||||
{"test2.heic", HEIF},
|
||||
{"test3.heic", HEIF},
|
||||
{"test.avif", AVIF},
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
|
|
@ -51,12 +52,16 @@ func TestDeterminateImageTypeName(t *testing.T) {
|
|||
{"test.svg", "svg"},
|
||||
// {"test.jp2", "magick"},
|
||||
{"test.heic", "heif"},
|
||||
{"test.avif", "avif"},
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
if file.expected == "heif" && VipsMajorVersion <= 8 && VipsMinorVersion < 8 {
|
||||
continue
|
||||
}
|
||||
if file.expected == "avif" && VipsMajorVersion <= 8 && VipsMinorVersion < 9 {
|
||||
continue
|
||||
}
|
||||
|
||||
img, _ := os.Open(path.Join("testdata", file.name))
|
||||
buf, _ := ioutil.ReadAll(img)
|
||||
|
|
@ -73,13 +78,16 @@ func TestIsTypeSupported(t *testing.T) {
|
|||
types := []struct {
|
||||
name ImageType
|
||||
}{
|
||||
{JPEG}, {PNG}, {WEBP}, {GIF}, {PDF}, {HEIF},
|
||||
{JPEG}, {PNG}, {WEBP}, {GIF}, {PDF}, {HEIF}, {AVIF},
|
||||
}
|
||||
|
||||
for _, n := range types {
|
||||
if n.name == HEIF && VipsMajorVersion <= 8 && VipsMinorVersion < 8 {
|
||||
continue
|
||||
}
|
||||
if n.name == AVIF && VipsMajorVersion <= 8 && VipsMinorVersion < 9 {
|
||||
continue
|
||||
}
|
||||
if IsTypeSupported(n.name) == false {
|
||||
t.Fatalf("Image type %s is not valid", ImageTypes[n.name])
|
||||
}
|
||||
|
|
@ -97,12 +105,16 @@ func TestIsTypeNameSupported(t *testing.T) {
|
|||
{"gif", true},
|
||||
{"pdf", true},
|
||||
{"heif", true},
|
||||
{"avif", true},
|
||||
}
|
||||
|
||||
for _, n := range types {
|
||||
if n.name == "heif" && VipsMajorVersion <= 8 && VipsMinorVersion < 8 {
|
||||
continue
|
||||
}
|
||||
if n.name == "avif" && VipsMajorVersion <= 8 && VipsMinorVersion < 9 {
|
||||
continue
|
||||
}
|
||||
if IsTypeNameSupported(n.name) != n.expected {
|
||||
t.Fatalf("Image type %s is not valid", n.name)
|
||||
}
|
||||
|
|
@ -121,6 +133,9 @@ func TestIsTypeSupportedSave(t *testing.T) {
|
|||
if VipsVersion >= "8.8.0" {
|
||||
types = append(types, struct{ name ImageType }{HEIF})
|
||||
}
|
||||
if VipsVersion >= "8.9.0" {
|
||||
types = append(types, struct{ name ImageType }{AVIF})
|
||||
}
|
||||
|
||||
for _, n := range types {
|
||||
if IsTypeSupportedSave(n.name) == false {
|
||||
|
|
@ -141,6 +156,7 @@ func TestIsTypeNameSupportedSave(t *testing.T) {
|
|||
{"pdf", false},
|
||||
{"tiff", VipsVersion >= "8.5.0"},
|
||||
{"heif", VipsVersion >= "8.8.0"},
|
||||
{"avif", VipsVersion >= "8.9.0"},
|
||||
}
|
||||
|
||||
for _, n := range types {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue