-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtinypng.go
More file actions
40 lines (29 loc) · 729 Bytes
/
tinypng.go
File metadata and controls
40 lines (29 loc) · 729 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package tinypng
import (
"os"
)
const (
apiUser = "api"
apiURL = "https://api.tinypng.com/"
)
// ShrinkFn allows you to Shrink using a
// filename instead of an open file handle.
func ShrinkFn(apiKey string, inputFilename string) (Response, error) {
inputFile, err := os.Open(inputFilename)
if err != nil {
return Response{}, err
}
return Shrink(apiKey, inputFile)
}
// Shrink allows you to shrink a PNG file using an open file handle.
func Shrink(apiKey string, inputFile *os.File) (Response, error) {
res, err := uploadPNG(apiKey, inputFile)
check(err)
defer res.Body.Close()
var r Response
r.PopulateFromHTTPResponse(res)
if res.StatusCode == 201 {
return r, nil
}
return r, e("unsuccessful")
}