Giter Site home page Giter Site logo

php-color-functions's Introduction

PHP Color Functions

Several simple functions for parsing CSS colors and converting colors formats.

Usage

Include the file src/color-functions.php into your project.

color_parse_string

Parse the CSS string value into an array of the values

ColorFunctions\color_parse_string( '#000000' ); // array('r' => 0, 'g' => 0, 'b' => 0)
ColorFunctions\color_parse_string( '#A00' ); // array('r' => 170, 'g' => 0, 'b' => 0)
ColorFunctions\color_parse_string( 'bLuE' ); // array('r' => 0, 'g' => 0, 'b' => 255)
ColorFunctions\color_parse_string( 'rgba( 255, 255, 255, 0.5 )' ); // array('r' => 255, 'g' => 255, 'b' => 255, 'a' => 0.5)
ColorFunctions\color_parse_string( 'hsl(120,100%, 50% )' ); // array('h' => 120, 's' => 1, 'l' => 0.5)

color_rgb_to_hex_string

Convert an RGB color into a CSS HEX string. The parameters are each ints from 0 to 255 and are red, blue, and green.

ColorFunctions\color_rgb_to_hex_string( 255, 0 0 ); // '#ff0000'

color_rgb_to_hsl

Convert an RGB to HSL color format. The parameters are each ints from 0 to 255. The return value is an array with keys for each part of HSL along with the original RGB values.

// Maroon
ColorFunctions\color_rgb_to_hsl( 128, 0, 0 ); // array('r' => 128, 'g' => 0, 'b' => 0, 'h' => 0, 's' => 1, 'l' => 0.25 )

color_rgb_to_hsv

Convert an RGB to HSV color format. The parameters are each ints from 0 to 255. The return value is an array with keys for each part of HSV along with the original RGB values.

ColorFunctions\color_rgb_to_hsv( 128, 0, 0 ); // array('r' => 128, 'g' => 0, 'b' => 0, 'h' => 0, 's' => 1.0, 'v' => 0.5 )

color_hsv_to_rgb

Convert an HSV color into an RGB color. The first parameter is hue which is a degree from 0 to 360. The next two are saturation and value (brightness) and are floats from 0 to 1.

ColorFunctions\color_hsv_to_rgb( 60, 1, 0.5 ); // array('r' => 128, 'g' => 128, 'b' => 0 )

License

MIT Licence, see LICENSE file

php-color-functions's People

Contributors

seamusleahy 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.