Code Monkey home page Code Monkey logo

img's Introduction

img docs

A collection of image manipulation tools. Each tool takes an input file from standard input, this needs to be in PNG, JPEG or GIF format. They output the resulting image (by default in PNG format) to standard output.

To install run,

$ go install hawx.me/code/img

You can then run go help and go help [command] for information.

The aim of img is not to be fast, if you want fast use GraphicsMagick, the aim is to be readable. Diving through endless files of C and C++ to find out how a certain effect is implemented is no fun, reading a single Go file is hopefully better.

Example (Command Line)

Here is an example: First we convert the image to greyscale using the values from the red colour channel, then boost the contrast slightly using a linear function, and finally tint the image with a dark red.

(img greyscale --red | \
  img contrast --linear --ratio 1.5 | \
  img tint --with '#83121344') < input.png > output.png

You can see here how easy it is to chain different tools together using pipes.

Example (Go)

You can also use the img libraries in Go code. We could rewrite the previous example as,

// example.go
package main

import (
  "hawx.me/code/img/contrast"
  "hawx.me/code/img/greyscale"
  "hawx.me/code/img/tint"

  "image/png"
  "os"
)

func main() {
  input, _ := os.Open(os.Args[1])
  img,   _ := png.Decode(input)

  img = greyscale.Red(img)
  img = contrast.Linear(img, 1.5)
  img = tint.Tint(img, color.NRGBA{131, 18, 19, 255})

  output, _ := os.Create(os.Args[2])
  png.Encode(output, img)
}

This can then be compiled and run like ./example input.png output.png.

img's People

Contributors

hawx avatar surma avatar

Watchers

 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.