Browse Source

Merge branch 'master' into version/3

DarthSim 4 years ago
parent
commit
bca4bddf53
3 changed files with 19 additions and 5 deletions
  1. 2 2
      docs/getting_the_image_info.md
  2. 17 1
      download.go
  3. 0 2
      imagemeta/heif.go

+ 2 - 2
docs/getting_the_image_info.md

@@ -29,7 +29,7 @@ The source URL can be provided as is, prepended by `/plain/` part:
 /plain/http://example.com/images/curiosity.jpg
 ```
 
-**📝Note:** If the sorce URL contains query string or `@`, you need to escape it.
+**📝Note:** If the source URL contains query string or `@`, you need to escape it.
 
 #### Base64 encoded
 
@@ -67,7 +67,7 @@ imgproxy responses with JSON body and returns the following info:
 }
 ```
 
-#### Exampple (mp4)
+#### Example (mp4)
 
 ```json
 {

+ 17 - 1
download.go

@@ -1,6 +1,7 @@
 package main
 
 import (
+	"compress/gzip"
 	"context"
 	"crypto/tls"
 	"fmt"
@@ -196,7 +197,22 @@ func downloadImage(imageURL string) (*imageData, error) {
 		return nil, err
 	}
 
-	imgdata, err := readAndCheckImage(res.Body, int(res.ContentLength))
+	body := res.Body
+	contentLength := int(res.ContentLength)
+
+	if res.Header.Get("Content-Encoding") == "gzip" {
+		gzipBody, errGzip := gzip.NewReader(res.Body)
+		if gzipBody != nil {
+			defer gzipBody.Close()
+		}
+		if errGzip != nil {
+			return nil, err
+		}
+		body = gzipBody
+		contentLength = 0
+	}
+
+	imgdata, err := readAndCheckImage(body, contentLength)
 	if err != nil {
 		return nil, err
 	}

+ 0 - 2
imagemeta/heif.go

@@ -210,8 +210,6 @@ func heifReadBoxes(d *heifData, r io.Reader) error {
 			if w > d.Width || h > d.Height {
 				d.Width, d.Height = w, h
 			}
-		case "mdat":
-			return errors.New("mdat box occurred before meta box")
 		default:
 			if err := heifDiscardN(r, boxDataSize); err != nil {
 				return err