hexcolor

package module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2023 License: MIT Imports: 2 Imported by: 3

README

hexcolor

Hex image/color implementation for go

Verify GoDoc

Usage

Download: go get -u github.com/g4s8/hexcolor

Example:

import "github.com/g4s8/hexcolor"
import "image/color"

func main() {
  var c color.Color
  c, err := hexcolor.Parse("#fc12bd")
  if err != nil {
    panic(err)
  }
}

See godoc for more details.

Contribution

Fork repository, clone it, make changes, check with go build && go test && go vet, push to new branch and submit a pull request.

Documentation

Overview

Package hexcolor allows to parse HEX representation of color which is frequently used for web colors and in other cases.

This package exposes single public entry point function:

Parse(hex string) (c color.RGBA, err error)

It uses implementation suggested in StackOverflow answer: https://stackoverflow.com/a/54200713/1723695 as "Fast Solution".

Supported formats:

  • RGB: #fc3 - red=ff, green=cc, blue=33
  • RRGGBB: #abcd02 - red=ab, green=cd, bluen=02
  • ARGB: #dfab - alpha=dd, RGB=fab
  • AARRGGBB: #c3a0b1c2 - alpha=c3 RRGGBB=a0b1c2

It supports uppercase and lowercase hex symbols. All hex symbols should start with `#` char.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidFormat = errors.New("invalid hex color format")

ErrInvalidFormat indicates that format of hex color string is invalid.

Functions

func Parse

func Parse(hex string) (c color.RGBA, err error)

Parse hex string to image/color It takes #RGB, #RRGGBB, #ARGB, #AARRGGBB strings as input and parse it to RGBA color from `color` Go package. In case of invalid hex, it returns error

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL