mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-08 23:18:19 -07:00
refactor(resize)
This commit is contained in:
parent
cdade0c27f
commit
40dd19fa6a
8 changed files with 207 additions and 141 deletions
|
|
@ -28,14 +28,16 @@ func TestResize(t *testing.T) {
|
|||
t.Fatal("Image is not jpeg")
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile("result.jpg", newImg, 0644)
|
||||
err = ioutil.WriteFile("fixtures/test_out.jpg", newImg, 0644)
|
||||
if err != nil {
|
||||
t.Fatal("Cannot save the image")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvert(t *testing.T) {
|
||||
options := Options{Width: 640, Height: 480, Crop: true, Type: PNG}
|
||||
width, height := 640, 480
|
||||
|
||||
options := Options{Width: width, Height: height, Crop: true, Type: PNG}
|
||||
img, err := os.Open("fixtures/test.jpg")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
@ -56,7 +58,47 @@ func TestConvert(t *testing.T) {
|
|||
t.Fatal("Image is not png")
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile("result.png", newImg, 0644)
|
||||
size, _ := Size(newImg)
|
||||
if size.Height != height || size.Width != width {
|
||||
t.Fatal("Invalid image size")
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile("fixtures/test_out.png", newImg, 0644)
|
||||
if err != nil {
|
||||
t.Fatal("Cannot save the image")
|
||||
}
|
||||
}
|
||||
|
||||
func TestResizePngWithTransparency(t *testing.T) {
|
||||
width, height := 300, 240
|
||||
|
||||
options := Options{Width: width, Height: height, Crop: true}
|
||||
img, err := os.Open("fixtures/transparent.png")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer img.Close()
|
||||
|
||||
buf, err := ioutil.ReadAll(img)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
newImg, err := Resize(buf, options)
|
||||
if err != nil {
|
||||
t.Errorf("Resize(imgData, %#v) error: %#v", options, err)
|
||||
}
|
||||
|
||||
if DetermineImageType(newImg) != PNG {
|
||||
t.Fatal("Image is not png")
|
||||
}
|
||||
|
||||
size, _ := Size(newImg)
|
||||
if size.Height != height || size.Width != width {
|
||||
t.Fatal("Invalid image size")
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile("fixtures/transparent_out.png", newImg, 0644)
|
||||
if err != nil {
|
||||
t.Fatal("Cannot save the image")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue