mirror of
https://github.com/fumiama/imgsz.git
synced 2026-06-12 06:00:28 +08:00
🎉 完成
This commit is contained in:
60
image_test.go
Normal file
60
image_test.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package imgsz
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSizes(t *testing.T) {
|
||||
f, err := os.Open("testdata/test.webp")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sz, n, err := DecodeSize(f)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if sz.Width != 3507 || sz.Height != 2480 || n != "webp" {
|
||||
t.Fatal(sz, n)
|
||||
}
|
||||
f.Close()
|
||||
|
||||
f, err = os.Open("testdata/test.jpg")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sz, n, err = DecodeSize(f)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if sz.Width != 858 || sz.Height != 1126 || n != "jpeg" {
|
||||
t.Fatal(sz, n)
|
||||
}
|
||||
f.Close()
|
||||
|
||||
f, err = os.Open("testdata/test.png")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sz, n, err = DecodeSize(f)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if sz.Width != 670 || sz.Height != 717 || n != "png" {
|
||||
t.Fatal(sz, n)
|
||||
}
|
||||
f.Close()
|
||||
|
||||
f, err = os.Open("testdata/test.gif")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sz, n, err = DecodeSize(f)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if sz.Width != 184 || sz.Height != 166 || n != "gif" {
|
||||
t.Fatal(sz, n)
|
||||
}
|
||||
f.Close()
|
||||
}
|
||||
Reference in New Issue
Block a user