From a792146837e38b1491654d255d1304f12e280102 Mon Sep 17 00:00:00 2001 From: Yoan Blanc Date: Thu, 22 Jun 2017 16:44:54 +0200 Subject: [PATCH] Add Image.Length() Signed-off-by: Yoan Blanc --- image.go | 7 ++++++- image_test.go | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/image.go b/image.go index efaffcb..7cff079 100644 --- a/image.go +++ b/image.go @@ -217,7 +217,12 @@ func (i *Image) Size() (ImageSize, error) { return Size(i.buffer) } -// Image returns the current resultant image image buffer. +// Image returns the current resultant image buffer. func (i *Image) Image() []byte { return i.buffer } + +// Length returns the size in bytes of the image buffer. +func (i *Image) Length() int { + return len(i.buffer) +} diff --git a/image_test.go b/image_test.go index 96fc4ad..aff3d3d 100644 --- a/image_test.go +++ b/image_test.go @@ -475,6 +475,17 @@ func TestImageSmartCrop(t *testing.T) { Write("fixtures/test_smart_crop.jpg", buf) } +func TestImageLength(t *testing.T) { + i := initImage("test.jpg") + + actual := i.Length() + expected := 53653 + + if expected != actual { + t.Errorf("Size in Bytes of the image doesn't correspond. %d != %d", expected, actual) + } +} + func initImage(file string) *Image { buf, _ := imageBuf(file) return NewImage(buf)