Image processing library and rendering toolkit for Go.

blend

Image processing library and rendering toolkit for Go. (WIP)

Installation:

This library is compatible with Go1.

go get github.com/phrozen/blend

Usage:

import "github.com/phrozen/blend"

Use this convenience function:

func BlendNewImage(dst, src image.Image, mode BlendFunc) image.Image {
  ...
}
// src is the top layer, dst is the bottom layer.

For example:

import "github.com/phrozen/blend"

// Read two images 'source' and 'destination' (image.Image)

// Blend source (top layer) into destination (bottom layer)
// using Color Burn blending mode.
img1 := blend.BlendNewImage(destination, source, blend.ColorBurn)


// Save img or blend it again applying another blend mode.
img2 := blend.BlendNewImage(img1, source, blend.Screen)

If you want to apply the Blend Mode to an image and modify it without returning a copy, you must provide a mutable image type, one that implements 'draw.Image' interface. Use this function.

func BlendImage(dst draw.Image, src image.Image, mode BlendFunc) {
  ...
}
// src is the top layer, dst is the bottom layer and image that will be applied to.

This function is faster as it does not copy the contents of the original image and applies the Blend Mode just to the intersection of both layers. Most images returned by the encoders of the standard library are already mutable as they implement the 'draw.Image' interface, but you will have to apply and interface/type assertion first.

(Note: jpeg decoder returns color images in YCbCr color mode that does not implement 'draw.Image', PNG decoder returns mostly RGBA family types and should work)

import "github.com/phrozen/blend"

// Read two images 'source' and 'destination' (image.Image)

dst, ok := destination.(draw.Image)
if ok {
  blend.BlendImage(dst, source, blend.ColorBurn)
  blend.BlendImage(dst, source, blend.Screen)
}

The package an be easily extended as it uses the standard library interfaces from 'image', 'image/draw' and 'image/color'.

type BlendFunc func(dst, src color.Color) color.Color

A BlendFunc is applied to each color (RGBA) of an image (although included blend modes does not use the Alpha channel atm). Just create your own BlendFunc to add custom functionality.

The library uses float64 internally for precision, math operations, and conversions to the 'image' interfaces.

At the moment it supports the following blending modes:

  • Darken
  • Multiply
  • Color Burn
  • Linear Burn
  • Darker Color

  • Lighten
  • Screen
  • Color Dodge
  • Linear Dodge
  • Lighter Color

  • Overlay
  • Soft Light
  • Hard Light
  • Vivid Light
  • Linear Light
  • Pin Light
  • Hard Mix

  • Difference
  • Exclusion
  • Substract
  • Divide

  • Hue
  • Saturation
  • Color
  • Luminosity

  • Add
  • Reflex
  • Phoenix

Notes:

  • Add, Reflex, and Phoenix modes are not in PSD.
  • Vivid Light produces different results than PSD, affects Hard Mix issue #2
  • Saturation, Color, and Luminosity modes produce different results than PSD, but the results are either identical to The GIMP or pretty similar. issue #3

Check the examples directory for more on blending modes.

More features to come.

License:

Copyright (c) 2012 Guillermo Estrada

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

MIT License

Owner
Guillermo Estrada
Day dreamer, analytical brainiac, shameless romantic, factual magician, practical poet, irrational empath, ninja coder and mind reader.
Guillermo Estrada
Similar Resources

An image server toolkit in Go (Golang)

An image server toolkit in Go (Golang)

Image Server An image server toolkit in Go (Golang) Features HTTP server Resize (GIFT, nfnt resize, Graphicsmagick) Rotate Crop Convert (JPEG, GIF (an

Dec 22, 2022

Canvas is a Go drawing library based on OpenGL or using software rendering that is very similar to the HTML5 canvas API

Canvas is a Go drawing library based on OpenGL or using software rendering that is very similar to the HTML5 canvas API

Go canvas Canvas is a pure Go library that provides drawing functionality as similar as possible to the HTML5 canvas API. It has nothing to do with HT

Jan 3, 2023

An API which allows you to upload an image and responds with the same image, stripped of EXIF data

strip-metadata This is an API which allows you to upload an image and responds with the same image, stripped of EXIF data. How to run You need to have

Nov 25, 2021

Easily customizable Social image (or Open graph image) generator

fancycard Easily customizable Social image (or Open graph image) generator Built with Go, Gin, GoQuery and Chromedp Build & Run Simply, Clone this rep

Jan 14, 2022

Imgpreview - Tiny image previews for HTML while the original image is loading

Imgpreview - Tiny image previews for HTML while the original image is loading

imgpreview This is a Go program that generates tiny blurry previews for images t

May 22, 2022

2D rendering for different output (raster, pdf, svg)

2D rendering for different output (raster, pdf, svg)

draw2d Package draw2d is a go 2D vector graphics library with support for multiple outputs such as images (draw2d), pdf documents (draw2dpdf), opengl

Dec 25, 2022

Go Graphics - 2D rendering in Go with a simple API.

Go Graphics - 2D rendering in Go with a simple API.

Go Graphics gg is a library for rendering 2D graphics in pure Go. Installation go get -u github.com/fogleman/gg Alternatively, you may use gopkg.in t

Dec 29, 2022

An experiment in rendering images with Slack custom emojis.

An experiment in rendering images with Slack custom emojis.

emojimage An experiment in rendering images with Slack custom emojis. Example Usage 1. Initializing your workspace First, you'll need to upload 1,332

Mar 12, 2022

Efficient moving window for high-speed data processing.

Moving Window Data Structure Copyright (c) 2012. Jake Brukhman. ([email protected]). All rights reserved. See the LICENSE file for BSD-style license. I

Sep 4, 2022
Comments
  • update

    update

    func getWidthAndHeight(img image.Image) (width, height int) { width = img.Bounds().Max.X - img.Bounds().Min.X height = img.Bounds().Max.Y - img.Bounds().Min.Y return }

    you should use the Dx() for the width and Dy() for the height

    func getWidthAndHeight(img image.Image) (width, height int) { width = img.Bounds().Dx() height = img.Bounds().Dy() return }

  • HSL Blend Modes

    HSL Blend Modes

    HUE blend mode produces the same effect on both Photoshop CS5 and GIMP. Current implementation reproduces both exactly.

    SATURATION, COLOR, and LUMINOSITY blending modes have different implementations on Photoshop CS5 and GIMP. Current implementation of the library produces exactly the expected result from COLOR that GIMP uses and very similar results on SATURATION and LUMINOSITY. But the Photoshop CS5 algorithms have different results on all 3 of them.

    To do:

    • Match SATURATION and LUMINOSITY blend modes to the GIMP implementation, it may have to do with rgb to hsl transformations, maybe try different implementation (but... ¿why HUE and COLOR work as expected?).
    • Find the correct Photoshop algorithms (if possible, ¿maybe reverse engineer them?) and implement them forking all functions that produce different results.
  • Vivid Light - Blend Mode

    Vivid Light - Blend Mode

    Vivid light algorithm (and hard mix because of that) does not produce the same effects as Adobe Photoshop CS 5. The vivid light algorithm used right now is working fine and it is not bugged, but produces slightly different results than PSD.

    This is the only vivid light algorithm I have found so far. Need to keep checking.

    Edit: GIMP does not have Vivid Light Layer Mode (or Hard Mix for that matter)

Related tags
Image - This repository holds supplementary Go image librariesThis repository holds supplementary Go image libraries

Go Images This repository holds supplementary Go image libraries. Download/Insta

Jan 5, 2022
A lightning fast image processing and resizing library for Go

govips A lightning fast image processing and resizing library for Go This package wraps the core functionality of libvips image processing library by

Jan 8, 2023
Go package for fast high-level image processing powered by libvips C library

bimg Small Go package for fast high-level image processing using libvips via C bindings, providing a simple programmatic API. bimg was designed to be

Jan 2, 2023
A library for basic image processing in Go.
A library for basic image processing in Go.

Imaging Package imaging provides basic image processing functions (resize, rotate, crop, brightness/contrast adjustments, etc.). All the image process

Nov 26, 2021
A library for basic image processing in Go.
A library for basic image processing in Go.

Imaging Package imaging provides basic image processing functions (resize, rotate, crop, brightness/contrast adjustments, etc.). All the image process

Nov 26, 2021
Storage and image processing server written in Go
Storage and image processing server written in Go

Mort An S3-compatible image processing server written in Go. Still in active development. Features HTTP server Resize, Rotate, SmartCrop Convert (JPEG

Jan 7, 2023
Image processing algorithms in pure Go
Image processing algorithms in pure Go

bild A collection of parallel image processing algorithms in pure Go. The aim of this project is simplicity in use and development over absolute high

Jan 6, 2023
Fast, simple, scalable, Docker-ready HTTP microservice for high-level image processing

imaginary Fast HTTP microservice written in Go for high-level image processing backed by bimg and libvips. imaginary can be used as private or public

Jan 3, 2023
Imaging is a simple image processing package for Go
Imaging is a simple image processing package for Go

Imaging Package imaging provides basic image processing functions (resize, rotate, crop, brightness/contrast adjustments, etc.). All the image process

Dec 30, 2022
Go Image Filtering Toolkit
Go Image Filtering Toolkit

GO IMAGE FILTERING TOOLKIT (GIFT) Package gift provides a set of useful image processing filters. Pure Go. No external dependencies outside of the Go

Dec 23, 2022