Giter VIP home page Giter VIP logo

colorist's Introduction

Colorist

PHP version Latest Stable Version Build Status codecov Scrutinizer Code Quality Total Downloads License

This package allows you to convert and manage color models.

Supported color models

  • RGB (RGBA)
  • HEX (HEXA)
  • html colors names

Short hex code is supported (#001122, #012, #00112233, #0123)

List of names colors you can see here

In the plans

  • HSL (HSLA)
  • HSV (HSVA)
  • CMYK
  • Lab

Requirements

  • PHP >= 7.1

Installation

Run command

$ composer require abyrate/colorist

Or add the following in your root composer.json file:

{
	"require": {
		"abyrate/colorist": "~2.0"
	}
}

and run command:

$ composer update

Usage

If you change the values of any model, the rest are automatically updated

Create

// Create an object in the standard way
$color = new \Abyrate\Colorist('rgb(55,191,0)');

// Create using static method
$color = \Abyrate\Colorist::create('rgb(55,191,0)');

Supported syntax:

  • 'rgb(0,0,0)' - rgb model
  • 'rgba(0,0,0,0)' - rgb model with alpha channel
  • '#000000' - hex model
  • '#00000000' - hex model with alpha channel
  • 'orange' - name model

Range of channels:

  • r, g, b - 0-255 (in the hex 00-ff)
  • alpha - 0-1 (float value. In the hex 00-ff)

Get

Channels

$colorist->getChannel('red');   // get red channel
$colorist->getChannel('green'); // get green channel
$colorist->getChannel('blue');  // get blue channel
$colorist->getChannel('alpha'); // get alpha channel
$colorist->getChannel('hex');   // get hex code (e.g. #15af45)
$colorist->getChannel('hexa');  // get hex code with alpha (e.g. #15af4505)
$colorist->getChannel('name');  // get color name (e.g. orange)

Models

$colorist->get('rgb');  // get rgb string (e.g. 15,156,10)
$colorist->get('rgba'); // get rgb string with alpha channel (e.g. 15,156,10,0.3)
$colorist->get('hex');  // get rgb in the hex format string (e.g. #15af45)
$colorist->get('hexa'); // get rgb with alpha channel in hex string (e.g. #15af4505)
$colorist->get('name'); // get color name (e.g. orange)

Set

Channels

$colorist->setChannel('red', 15);           // set red channel
$colorist->setChannel('green', 20);         // set green channel
$colorist->setChannel('blue', 25);          // set blue channel
$colorist->setChannel('alpha', 0.3);        // set alpha channel
$colorist->setChannel('hex', '#004');       // set hex code
$colorist->setChannel('hexa', '#00112233'); // set hex code with alpha
$colorist->setChannel('name', 'orange');    // set color name

Models

$colorist->set('rgb', 'rgb(0,15,36)');       // set rgb string
$colorist->set('rgba', 'rgb(0,15,36, 0.1)'); // set rgb string with alpha channel
$colorist->set('hex', '#123');               // set rgb in the hex format string
$colorist->set('hexa', '#1234');             // set rgb with alpha channel in hex string
$colorist->set('name', 'orange');            // set color name (e.g. orange)

API documentation

colorist's People

Contributors

andyboldyrev avatar asboldyrev avatar scrutinizer-auto-fixer avatar

Stargazers

 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.