Code Monkey home page Code Monkey logo

tinify-go's Introduction

tinify-go

Golang client for the Tinify API

Usage

Basic Compressing images

This very simple. Just set your API key, then call with your input filename and output filename. As follows:

package main

import (
	"fmt"
	"github.com/tianhe1986/tinify-go/tinify"
)

func main() {
	var key string = "XXXXXX"
	tinify.SetKey(key)
	
	// optional, set the URL of your proxy server
	// tinify.SetProxy("http://user:[email protected]:8080")
	
	// from file
	tinify.FromFile("./1.jpg").ToFile("./test1.jpg")
	
	// from url
	tinify.FromUrl("https://XXXXXX.png").ToFile("./test2.png")
}

Resize

There are 4 ways your image will be resized according to the official document

So you could call Resize with different method name, such as follows:

package main

import (
	"fmt"
	"github.com/tianhe1986/tinify-go/tinify"
)

func main() {
	var key string = "XXXXXX"
	tinify.SetKey(key)
	
	// optional, set the URL of your proxy server
	// tinify.SetProxy("http://user:[email protected]:8080")
	
	// scale with width
	tinify.FromFile("./1.jpg").Resize("scale", 200, 0).ToFile("./test1-scale-width.jpg")

	// scale with height
	tinify.FromFile("./1.jpg").Resize("scale", 0, 400).ToFile("./test1-scale-height.jpg")

	// fit
	tinify.FromFile("./1.jpg").Resize("fit", 200, 200).ToFile("./test1-fit.jpg")

	// cover
	tinify.FromFile("./1.jpg").Resize("cover", 300, 300).ToFile("./test1-cover.jpg")

	// thumb
	tinify.FromFile("./1.jpg").Resize("thumb", 250, 250).ToFile("./test1-thumb.jpg")
}

tinify-go's People

Contributors

tianhe1986 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.