mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-09 07:28:44 -07:00
feat(#1): initial implementation
This commit is contained in:
parent
8bcefc7736
commit
63f4b01c8d
14 changed files with 465 additions and 1 deletions
38
resize_test.go
Normal file
38
resize_test.go
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
package bimg
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestResize(t *testing.T) {
|
||||
options := Options{Width: 800, Height: 600, Crop: false}
|
||||
img, err := os.Open("fixtures/space.jpg")
|
||||
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)
|
||||
}
|
||||
|
||||
debug("Image %s", http.DetectContentType(newImg))
|
||||
|
||||
if http.DetectContentType(newImg) != "image/jpeg" {
|
||||
t.Fatal("Image is not jpeg")
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile("fixtures/test.jpg", newImg, 0644)
|
||||
if err != nil {
|
||||
t.Fatal("Cannot save the image")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue