Git Product home page Git Product logo

php-hexer's Introduction

HEX color modifier โ€” brightness, conversion and more.

Ever wanted to lighten or darken a hex in PHP? This package will allow you to. It's easy to use, fully tested and is very lightweight.

+ Added the ability to convert to RGB

Build Status Coverage StyleCI Status Total Downloads Latest Stable Version License

Installation

You just require using composer and you're good to go!

composer require lasserafn/php-hexer

Usage

As with installation, usage is quite simple.

use LasseRafn\Hexer\Hex;

// Lighten
$hex = new Hex('#333'); // You can leave out the hashtag if you wish.
echo $hex->lighten(15); // Output: #595959 (if you left out the hashtag, it would not be included in the output either)

// Darken
$hex = new Hex('ffffff');
echo $hex->darken(15); // Output: d9d9d9

// To RGB
$hex = new Hex('007F00');
$hex->lighten(50)->toRgb(); // Returns: ['r' => 128, 'g' => 255, 'b' => 128]

Methods

The constructor accepts one parameter (hex) which can optionally contain a hashtag (#). The length has to be between 3-6 characters (without the hashtag).

lighten($percentage)

Will lighten the color by X percentage. Percentage must be between 0-100. An exception will be thrown otherwise.

darken($percentage)

Will darken the color by X percentage. Percentage must be between 0-100. An exception will be thrown otherwise.

toRgb()

Will return the hex as RGB (an array of r, g, b).

Exceptions

If you input a HEX which is less than 3 characters of length, or greater than 6, an exception will be thrown. Similar with percentages, if you specify a percentage less than zero, or greater than 100, an exception will be thrown. If the percentage is zero, the hex itself will simply be returned.

Requirements

  • PHP 5.6, 7.0 or 7.1

php-hexer's People

Contributors

davejtoews avatar lasserafn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

davejtoews

php-hexer's Issues

Php 8 support

The composer.json file specifies PHP versions which do not include php 8.

It may well run in php 8, but composer can't resolve a compatible version when php 8 is a requirement.

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.