Giter Site home page Giter Site logo

color's Introduction

Build Status StyleCI

Stories in Ready Stories in Progress Stories in Done

A micro PHP package to convert and alter colors! ๐Ÿ”ฅ

Contents of this document:

Installation

You can install this package through composer. To install the latest version in to your project use the following command:

composer require liquidpineapple/color

This package requires PHP 7.0 or higher.

Documentation

Table of contents:

  1. Conversion

    b) Output

    a) Types

  2. Alteration

    a) Lightness

    b) Saturation

1. Conversion

You can use this package to convert colors to different notations. An example might be converting HEX to RGB:

<?php

use Liquidpineapple\Color;

$rgbColor = Color::fromHEX('#1E90FF')->toRGB();
// [30, 144, 255]

1a. Output

In some cases you might want an output like rgb(30, 144, 255). This can be done using the following method:

<?php

use Liquidpineapple\Color;

$rgbColor = Color::fromHEX('#1E90FF')->toRGBString();
// rgb(30, 144, 255)

1b. Types

You can convert from the following types:

  • HEX: fromHEX($hex)
  • RGB: fromHEX($red, $green, $blue)
  • HSL: fromHSL($hue, $saturation, $lightness)
  • HSV: fromHSV($hue, $saturation, $value)

To the following types

  • HEX: toHEX() & toHEXString() (alias of toHEX())
  • RGB: toRGB() & toRGBString()
  • HSL: toHSL() & toHSLString()
  • HSV: toHSV() & toHSVString()

2. Alteration

Sometimes just conversion isn't enough, in some cases you might want to darken or saturate a color. Luckily, this is a breeze with this package.

2a. Lightness

You can alter the lightness of the color using the following methods:

  • lighten($amount)
  • darken($amount)

The amount in both message is a percentage. An example:

<?php

use Liquidpineapple\Color;

$primaryColor = '#1E90FF';

$secondaryColor = Color::fromHEX('#1E90FF')->darken(10)->toHEX();
// #2A8FF4

2b. Saturation

Just as with lightness you can alter the saturation of a given color. This can be done using the following methods:

  • saturate($amount)
  • desaturate($amount)

The amount in both message is a percentage. An example:

<?php

use Liquidpineapple\Color;

$dullColor = '#C44';

$exitingColor = Color::fromHEX('#C44')->saturate(10)->toHEX();
// #D33C3C

Contributing

Did we miss something, or do you have cool ideas? Feel free to contribute!

How to contribute:

  1. Fork this repository.
  2. Write code (with comments).
  3. Write tests (100% coverage).
  4. Create a pull-request.
  5. Profit!

color's People

Contributors

frontendcoffee avatar waffle-iron avatar

Watchers

 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.