From 188325d0f47efc0a284fe666fec4873a6f1c03bf Mon Sep 17 00:00:00 2001 From: Tomas Aparicio Date: Wed, 18 Mar 2015 01:34:14 +0100 Subject: [PATCH] feat(#13): infer image type with go net/http primitive --- vips.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/vips.go b/vips.go index 21aa433..7806254 100644 --- a/vips.go +++ b/vips.go @@ -7,10 +7,10 @@ package vips import "C" import ( - "bytes" "errors" "fmt" "math" + "net/http" "os" "runtime" "unsafe" @@ -93,15 +93,13 @@ func Resize(buf []byte, o Options) ([]byte, error) { debug("%#+v", o) // detect (if possible) the file type - chunk := buf[:2] typ := UNKNOWN - switch { - case bytes.Equal(chunk, MARKER_JPEG): + case http.DetectContentType(buf) == "image/jpeg": typ = JPEG - case bytes.Equal(chunk, MARKER_WEBP): + case http.DetectContentType(buf) == "image/webp": typ = WEBP - case bytes.Equal(chunk, MARKER_PNG): + case http.DetectContentType(buf) == "image/png": typ = PNG default: return nil, errors.New("unknown image format")