Discover Packages
github.com/gwpp/tinify-go
module
Version:
v0.0.0-...-77b9df1
Opens a new window with list of versions in this module.
Published: Jun 13, 2017
License: MIT
Opens a new window with license information.
README
README
ยถ
Tinify API client for Golang
๐ ๅฝๅ
็ๆๅ็่ฟ้
Golang client for the Tinify API, used for TinyPNG and TinyJPG . Tinify compresses or resize your images intelligently. Read more at http://tinify.com .
Documentation
Go to the documentation for the HTTP client .
Installation
Install the API client with go get.
go get -u github.com/gwpp/tinify-go
Usage
About key
Get your API key from https://tinypng.com/developers
Compress
func TestCompressFromFile(t *testing.T) {
Tinify.SetKey(Key)
source, err := Tinify.FromFile("./test.jpg")
if err != nil {
t.Error(err)
return
}
err = source.ToFile("./test_output/CompressFromFile.jpg")
if err != nil {
t.Error(err)
return
}
t.Log("Compress successful")
}
Resize
func TestResizeFromBuffer(t *testing.T) {
Tinify.SetKey(Key)
buf, err := ioutil.ReadFile("./test.jpg")
if err != nil {
t.Error(err)
return
}
source, err := Tinify.FromBuffer(buf)
if err != nil {
t.Error(err)
return
}
err = source.Resize(&Tinify.ResizeOption{
Method: Tinify.ResizeMethodScale,
Width: 200,
})
if err != nil {
t.Error(err)
return
}
err = source.ToFile("./test_output/ResizesFromBuffer.jpg")
if err != nil {
t.Error(err)
return
}
t.Log("Resize successful")
}
Notice:
Tinify.ResizeMethod support scale, fit and cover. If used fit or cover, you must provide both a width and a height. But used scale, you must provide either a target width or a target height, but not both.
More usage, please see tinify_test.go
Running tests
cd $GOPATH/src/github.com/gwpp/tinify-go
go test
License
This software is licensed under the MIT License. View the license .
Expand โพ
Collapse โด
Directories
ยถ
Click to show internal directories.
Click to hide internal directories.