Skip to content

Commit

Permalink
feat(DAddYE#13): infer image type with go net/http primitive
Browse files Browse the repository at this point in the history
  • Loading branch information
h2non committed Mar 18, 2015
1 parent 97117fc commit 188325d
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions vips.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ package vips
import "C"

import (
"bytes"
"errors"
"fmt"
"math"
"net/http"
"os"
"runtime"
"unsafe"
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 188325d

Please sign in to comment.