Documentation ¶
Overview ¶
Package tinypng is `tinypng.com` API client implementation.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a tinypng client implementation.
func NewClient ¶
func NewClient(apiKey string, options ...ClientOption) *Client
NewClient creates a new tinypng client instance. Options can be used to fine client tuning.
func (*Client) Compress ¶
Compress uploads image content from the provided source to the tinypng server for compression. When the process is done, the compression result (just information, not compressed image content) will be returned. If the provided source is also an io.Closer - it will be closed automatically by the HTTP client (if the default HTTP client is used).
Example (And_Download) ¶
package main import ( "context" "fmt" "os" _ "embed" "gh.tarampamp.am/tinifier/v4/pkg/tinypng" ) func main() { c := tinypng.NewClient("YOUR-API-KEY") srcFile, err := os.OpenFile("/tmp/image.png", os.O_RDONLY, 0) if err != nil { panic(err) } defer srcFile.Close() info, err := c.Compress(context.TODO(), srcFile) if err != nil { panic(err) } destFile, err := os.OpenFile("/tmp/image_compressed.png", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666) if err != nil { panic(err) } defer destFile.Close() if err = info.Download(context.TODO(), destFile); err != nil { panic(err) } fmt.Printf("%+v\n", info) }
Output:
type ClientOption ¶
type ClientOption func(*Client)
ClientOption allows to set up some internal client properties from outside.
func WithHTTPClient ¶
func WithHTTPClient(httpClient httpClient) ClientOption
WithHTTPClient setups allows to pass custom HTTP client implementation.
type Compressed ¶
type Compressed struct {
// contains filtered or unexported fields
}
Compressed represents tinypng compression result.
func (Compressed) Dimensions ¶
func (c Compressed) Dimensions() (width, height uint32)
Dimensions returns the dimensions of the compressed image.
func (Compressed) Download ¶
Download image from remote server and write to the passed destination.
If the provided source is also an io.Closer - it will be closed automatically by the HTTP client (if the default HTTP client is used).
func (Compressed) Size ¶
func (c Compressed) Size() uint64
Size returns the size (in bytes) of the compressed image.
func (Compressed) Type ¶
func (c Compressed) Type() string
Type returns the type of the compressed image.
func (Compressed) URL ¶
func (c Compressed) URL() string
URL returns the URL of the compressed image.
func (Compressed) UsedQuota ¶
func (c Compressed) UsedQuota() uint64
UsedQuota returns the used quota value.