All Projects → disintegration → Gift

disintegration / Gift

Licence: mit
Go Image Filtering Toolkit

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Gift

Gaussianblur
An easy and fast library to apply gaussian blur filter on any images. 🎩
Stars: ✭ 473 (-67.89%)
Mutual labels:  image-processing, image, filters
Smartcircle
✂️Automatically determine where to crop a circular image out of a rectangular.
Stars: ✭ 29 (-98.03%)
Mutual labels:  image-processing, image
Metalpetal
A GPU accelerated image and video processing framework built on Metal.
Stars: ✭ 907 (-38.42%)
Mutual labels:  image-processing, image
Serverless Image Processor
AWS Lambda image processor
Stars: ✭ 106 (-92.8%)
Mutual labels:  image-processing, image
Scrimage
Java, Scala and Kotlin image processing library
Stars: ✭ 792 (-46.23%)
Mutual labels:  image, filters
Cometa
Super fast, on-demand and on-the-fly, image processing.
Stars: ✭ 8 (-99.46%)
Mutual labels:  image-processing, image
Opencv Face Filters
Snapchat-like Face Filters in OpenCV
Stars: ✭ 51 (-96.54%)
Mutual labels:  image-processing, filters
Compressor
An easy to use and well designed image compress library for Android, based on Android native image library. Put forward a framework for quick switch from different compress algorithm.
Stars: ✭ 476 (-67.68%)
Mutual labels:  image-processing, image
Skrop
Image transformation service using libvips, based on Skipper.
Stars: ✭ 71 (-95.18%)
Mutual labels:  image-processing, image
Damselfly
Damselfly is a server-based Digital Asset Management system for photographs. The goal of Damselfly is to index an extremely large collection of images, and allow easy search and retrieval of those images, using metadata such as the IPTC keyword tags, as well as the folder and file names.
Stars: ✭ 86 (-94.16%)
Mutual labels:  image-processing, image
Processing Imageprocessing
Collection of basic image processing algorithms for processing
Stars: ✭ 87 (-94.09%)
Mutual labels:  image-processing, image
Flyimg
Dockerized PHP7 application runs as a Microservice to resize and crop images on the fly. Get optimised images with MozJPEG, WebP or PNG using ImageMagick. Includes face detection, cropping, face blurring, image rotation and many other options. Abstract storage based on FlySystem in order to store images on any provider (local, AWS S3...).
Stars: ✭ 762 (-48.27%)
Mutual labels:  image-processing, image
Oblique
With Oblique explore new styles of displaying images
Stars: ✭ 633 (-57.03%)
Mutual labels:  image-processing, image
Detection Of Breast Cancer Using Neural Networks
This project is made in Matlab Platform and it detects whether a person has cancer or not by taking into account his/her mammogram.
Stars: ✭ 15 (-98.98%)
Mutual labels:  image-processing, image
Pixload
Image Payload Creating/Injecting tools
Stars: ✭ 586 (-60.22%)
Mutual labels:  image-processing, image
Imagemin Module
Automatically optimize (compress) all images used in Nuxt.js
Stars: ✭ 37 (-97.49%)
Mutual labels:  image-processing, image
Imgproxy
Fast and secure standalone server for resizing and converting remote images
Stars: ✭ 5,688 (+286.15%)
Mutual labels:  image-processing, image
Pyautolens
PyAutoLens: Open Source Strong Gravitational Lensing
Stars: ✭ 90 (-93.89%)
Mutual labels:  image-processing, image
Pillow
The friendly PIL fork (Python Imaging Library)
Stars: ✭ 9,241 (+527.36%)
Mutual labels:  image-processing, image
Png To Ico
convert png to ico format
Stars: ✭ 88 (-94.03%)
Mutual labels:  image-processing, image

GO IMAGE FILTERING TOOLKIT (GIFT)

GoDoc Build Status Coverage Status Go Report Card

Package gift provides a set of useful image processing filters.

Pure Go. No external dependencies outside of the Go standard library.

INSTALLATION / UPDATING

go get -u github.com/disintegration/gift

DOCUMENTATION

http://godoc.org/github.com/disintegration/gift

QUICK START

// 1. Create a new filter list and add some filters.
g := gift.New(
	gift.Resize(800, 0, gift.LanczosResampling),
	gift.UnsharpMask(1, 1, 0),
)

// 2. Create a new image of the corresponding size.
// dst is a new target image, src is the original image.
dst := image.NewRGBA(g.Bounds(src.Bounds()))

// 3. Use the Draw func to apply the filters to src and store the result in dst.
g.Draw(dst, src)

USAGE

To create a sequence of filters, the New function is used:

g := gift.New(
	gift.Grayscale(),
	gift.Contrast(10),
)

Filters also can be added using the Add method:

g.Add(GaussianBlur(2))

The Bounds method takes the bounds of the source image and returns appropriate bounds for the destination image to fit the result (for example, after using Resize or Rotate filters).

dst := image.NewRGBA(g.Bounds(src.Bounds()))

There are two methods available to apply these filters to an image:

  • Draw applies all the added filters to the src image and outputs the result to the dst image starting from the top-left corner (Min point).
g.Draw(dst, src)
  • DrawAt provides more control. It outputs the filtered src image to the dst image at the specified position using the specified image composition operator. This example is equivalent to the previous:
g.DrawAt(dst, src, dst.Bounds().Min, gift.CopyOperator)

Two image composition operators are supported by now:

  • CopyOperator - Replaces pixels of the dst image with pixels of the filtered src image. This mode is used by the Draw method.
  • OverOperator - Places the filtered src image on top of the dst image. This mode makes sence if the filtered src image has transparent areas.

Empty filter list can be used to create a copy of an image or to paste one image to another. For example:

// Create a new image with dimensions of the bgImage.
dstImage := image.NewRGBA(bgImage.Bounds())
// Copy the bgImage to the dstImage.
gift.New().Draw(dstImage, bgImage)
// Draw the fgImage over the dstImage at the (100, 100) position.
gift.New().DrawAt(dstImage, fgImage, image.Pt(100, 100), gift.OverOperator)

SUPPORTED FILTERS

  • Transformations

    • Crop(rect image.Rectangle)
    • CropToSize(width, height int, anchor Anchor)
    • FlipHorizontal()
    • FlipVertical()
    • Resize(width, height int, resampling Resampling)
    • ResizeToFill(width, height int, resampling Resampling, anchor Anchor)
    • ResizeToFit(width, height int, resampling Resampling)
    • Rotate(angle float32, backgroundColor color.Color, interpolation Interpolation)
    • Rotate180()
    • Rotate270()
    • Rotate90()
    • Transpose()
    • Transverse()
  • Adjustments & effects

    • Brightness(percentage float32)
    • ColorBalance(percentageRed, percentageGreen, percentageBlue float32)
    • ColorFunc(fn func(r0, g0, b0, a0 float32) (r, g, b, a float32))
    • Colorize(hue, saturation, percentage float32)
    • ColorspaceLinearToSRGB()
    • ColorspaceSRGBToLinear()
    • Contrast(percentage float32)
    • Convolution(kernel []float32, normalize, alpha, abs bool, delta float32)
    • Gamma(gamma float32)
    • GaussianBlur(sigma float32)
    • Grayscale()
    • Hue(shift float32)
    • Invert()
    • Maximum(ksize int, disk bool)
    • Mean(ksize int, disk bool)
    • Median(ksize int, disk bool)
    • Minimum(ksize int, disk bool)
    • Pixelate(size int)
    • Saturation(percentage float32)
    • Sepia(percentage float32)
    • Sigmoid(midpoint, factor float32)
    • Sobel()
    • Threshold(percentage float32)
    • UnsharpMask(sigma, amount, threshold float32)

FILTER EXAMPLES

The original image:

Resulting images after applying some of the filters:

name / result name / result name / result name / result
resize crop_to_size rotate_180 rotate_30
brightness_increase brightness_decrease contrast_increase contrast_decrease
saturation_increase saturation_decrease gamma_1.5 gamma_0.5
gaussian_blur unsharp_mask sigmoid pixelate
colorize grayscale sepia invert
mean median minimum maximum
hue_rotate color_balance color_func convolution_emboss

Here's the code that produces the above images:

package main

import (
	"image"
	"image/color"
	"image/png"
	"log"
	"os"

	"github.com/disintegration/gift"
)

func main() {
	src := loadImage("testdata/src.png")

	filters := map[string]gift.Filter{
		"resize":               gift.Resize(100, 0, gift.LanczosResampling),
		"crop_to_size":         gift.CropToSize(100, 100, gift.LeftAnchor),
		"rotate_180":           gift.Rotate180(),
		"rotate_30":            gift.Rotate(30, color.Transparent, gift.CubicInterpolation),
		"brightness_increase":  gift.Brightness(30),
		"brightness_decrease":  gift.Brightness(-30),
		"contrast_increase":    gift.Contrast(30),
		"contrast_decrease":    gift.Contrast(-30),
		"saturation_increase":  gift.Saturation(50),
		"saturation_decrease":  gift.Saturation(-50),
		"gamma_1.5":            gift.Gamma(1.5),
		"gamma_0.5":            gift.Gamma(0.5),
		"gaussian_blur":        gift.GaussianBlur(1),
		"unsharp_mask":         gift.UnsharpMask(1, 1, 0),
		"sigmoid":              gift.Sigmoid(0.5, 7),
		"pixelate":             gift.Pixelate(5),
		"colorize":             gift.Colorize(240, 50, 100),
		"grayscale":            gift.Grayscale(),
		"sepia":                gift.Sepia(100),
		"invert":               gift.Invert(),
		"mean":                 gift.Mean(5, true),
		"median":               gift.Median(5, true),
		"minimum":              gift.Minimum(5, true),
		"maximum":              gift.Maximum(5, true),
		"hue_rotate":           gift.Hue(45),
		"color_balance":        gift.ColorBalance(10, -10, -10),
		"color_func": gift.ColorFunc(
			func(r0, g0, b0, a0 float32) (r, g, b, a float32) {
				r = 1 - r0   // invert the red channel
				g = g0 + 0.1 // shift the green channel by 0.1
				b = 0        // set the blue channel to 0
				a = a0       // preserve the alpha channel
				return r, g, b, a
			},
		),
		"convolution_emboss": gift.Convolution(
			[]float32{
				-1, -1, 0,
				-1, 1, 1,
				0, 1, 1,
			},
			false, false, false, 0.0,
		),
	}

	for name, filter := range filters {
		g := gift.New(filter)
		dst := image.NewNRGBA(g.Bounds(src.Bounds()))
		g.Draw(dst, src)
		saveImage("testdata/dst_"+name+".png", dst)
	}
}

func loadImage(filename string) image.Image {
	f, err := os.Open(filename)
	if err != nil {
		log.Fatalf("os.Open failed: %v", err)
	}
	defer f.Close()
	img, _, err := image.Decode(f)
	if err != nil {
		log.Fatalf("image.Decode failed: %v", err)
	}
	return img
}

func saveImage(filename string, img image.Image) {
	f, err := os.Create(filename)
	if err != nil {
		log.Fatalf("os.Create failed: %v", err)
	}
	defer f.Close()
	err = png.Encode(f, img)
	if err != nil {
		log.Fatalf("png.Encode failed: %v", err)
	}
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].