mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-13 01:10:29 -07:00
parent
b93919d182
commit
16576f49c9
6 changed files with 170 additions and 52 deletions
|
|
@ -10,6 +10,11 @@ func TestImageResize(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Errorf("Cannot process the image: %#v", err)
|
||||
}
|
||||
|
||||
if assertSize(buf, 300, 240) {
|
||||
t.Error("Invalid image size")
|
||||
}
|
||||
|
||||
Write("fixtures/test_resize_out.jpg", buf)
|
||||
}
|
||||
|
||||
|
|
@ -18,17 +23,79 @@ func TestImageExtract(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Errorf("Cannot process the image: %#v", err)
|
||||
}
|
||||
|
||||
if assertSize(buf, 300, 300) {
|
||||
t.Error("Invalid image size")
|
||||
}
|
||||
|
||||
Write("fixtures/test_extract_out.jpg", buf)
|
||||
}
|
||||
|
||||
func TestImageEnlarge(t *testing.T) {
|
||||
buf, err := initImage("test.png").Enlarge(500, 380)
|
||||
if err != nil {
|
||||
t.Errorf("Cannot process the image: %#v", err)
|
||||
}
|
||||
|
||||
if assertSize(buf, 500, 380) {
|
||||
t.Error("Invalid image size")
|
||||
}
|
||||
|
||||
Write("fixtures/test_enlarge_out.jpg", buf)
|
||||
}
|
||||
|
||||
func TestImageCrop(t *testing.T) {
|
||||
buf, err := initImage("test.jpg").Crop(800, 600)
|
||||
if err != nil {
|
||||
t.Errorf("Cannot process the image: %#v", err)
|
||||
}
|
||||
|
||||
if assertSize(buf, 800, 600) {
|
||||
t.Error("Invalid image size")
|
||||
}
|
||||
|
||||
Write("fixtures/test_crop_out.jpg", buf)
|
||||
}
|
||||
|
||||
func TestImageCropByWidth(t *testing.T) {
|
||||
buf, err := initImage("test.jpg").CropByWidth(600)
|
||||
if err != nil {
|
||||
t.Errorf("Cannot process the image: %#v", err)
|
||||
}
|
||||
|
||||
if assertSize(buf, 600, 375) {
|
||||
t.Error("Invalid image size")
|
||||
}
|
||||
|
||||
Write("fixtures/test_crop_width_out.jpg", buf)
|
||||
}
|
||||
|
||||
func TestImageCropByHeight(t *testing.T) {
|
||||
buf, err := initImage("test.jpg").CropByHeight(300)
|
||||
if err != nil {
|
||||
t.Errorf("Cannot process the image: %#v", err)
|
||||
}
|
||||
|
||||
if assertSize(buf, 800, 480) {
|
||||
t.Error("Invalid image size")
|
||||
}
|
||||
|
||||
Write("fixtures/test_crop_height_out.jpg", buf)
|
||||
}
|
||||
|
||||
func TestImageThumbnail(t *testing.T) {
|
||||
buf, err := initImage("test.jpg").Thumbnail(100)
|
||||
if err != nil {
|
||||
t.Errorf("Cannot process the image: %#v", err)
|
||||
}
|
||||
|
||||
if assertSize(buf, 100, 100) {
|
||||
t.Error("Invalid image size")
|
||||
}
|
||||
|
||||
Write("fixtures/test_thumbnail_out.jpg", buf)
|
||||
}
|
||||
|
||||
func TestImageFlip(t *testing.T) {
|
||||
buf, err := initImage("test.jpg").Flip()
|
||||
if err != nil {
|
||||
|
|
@ -37,14 +104,6 @@ func TestImageFlip(t *testing.T) {
|
|||
Write("fixtures/test_flip_out.jpg", buf)
|
||||
}
|
||||
|
||||
func TestImageThumbnail(t *testing.T) {
|
||||
buf, err := initImage("test.jpg").Thumbnail(100)
|
||||
if err != nil {
|
||||
t.Errorf("Cannot process the image: %#v", err)
|
||||
}
|
||||
Write("fixtures/test_thumbnail_out.jpg", buf)
|
||||
}
|
||||
|
||||
func TestImageRotate(t *testing.T) {
|
||||
buf, err := initImage("test_flip_out.jpg").Rotate(90)
|
||||
if err != nil {
|
||||
|
|
@ -81,3 +140,14 @@ func initImage(file string) *Image {
|
|||
buf, _ := Read(path.Join("fixtures", file))
|
||||
return NewImage(buf)
|
||||
}
|
||||
|
||||
func assertSize(buf []byte, width, height int) bool {
|
||||
size, err := NewImage(buf).Size()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
if size.Width != 220 || size.Height != 300 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue