Golang client for the Tinify API.
Switch branches/tags
Nothing to show
Clone or download
Latest commit 77b9df1 Jun 13, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test_output compress is ok Jun 11, 2017
tinify modify name Jun 13, 2017
.gitignore 图片压缩OK Jun 12, 2017
LICENSE Initial commit Jun 6, 2017
README.md README Jun 13, 2017
test.jpg init Jun 6, 2017
tinify_test.go modify name Jun 13, 2017

README.md

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.