Giter Site home page Giter Site logo

saltnpixels / phpcolors Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mexitek/phpcolors

0.0 1.0 0.0 299 KB

A series of methods that let you manipulate colors. Just incase you ever need different shades of one color on the fly.

Home Page: http://mexitek.github.com/phpColors/

PHP 100.00%

phpcolors's Introduction

Last Build: Build Status

Installation

Composer

Simply add mexitek/phpcolors to composer.json using dev-master.

composer require mexitek/phpcolors dev-master

How it works

Instantiate an object of the color class with a hex color string $foo = new Color("336699"). That's it! Now, call the methods you need for different color variants.

Available Methods

  • darken( [$amount] ) : Allows you to obtain a darker shade of your color. Optionally you can decide to darken using a desired percentage.
  • lighten( [$amount] ) : Allows you to obtain a lighter shade of your color. Optionally you can decide to lighten using a desired percentage.
  • mix($hex, [$amount] ) : Allows you to mix another color to your color. Optionally you can decide to set the percent of second color or original color amount is ranged -100..0.100.
  • isLight( [$hex] ) : Determins whether your color (or the provide param) is considered a "light" color. Returns TRUE if color is light.
  • isDark( [$hex] ) : Determins whether your color (or the provide param) is considered a "dark" color. Returns TRUE if color is dark.
  • makeGradient( [$amount] ) : Returns an array with 2 indices light and dark, the initial color will either be selected for light or dark depending on its brightness, then the other color will be generated. The optional param allows for a static lighten or darkened amount.
  • complementary() : Returns the color "opposite" or complementary to your color.
  • getHex() : Returns the original hex color.
  • getHsl() : Returns HSL array for your color.
  • getRgb() : Returns RGB array for your color.

Auto lightens/darkens by 10% for sexily-subtle gradients

/**
 * Using The Class
 */

use Mexitek\PHPColors\Color;

// Initialize my color
$myBlue = new Color("#336699");

echo $myBlue->darken();
// 1a334d

echo $myBlue->lighten();
// 8cb3d9

echo $myBlue->isLight();
// false

echo $myBlue->isDark();
// true

echo $myBlue->complementary();
// 996633

echo $myBlue->getHex();
// 336699

print_r( $myBlue->getHsl() );
// array( "H"=> 210, "S"=> 0.5, "L"=>0.4 );

print_r( $myBlue->getRgb() );
// array( "R"=> 51, "G"=> 102, "B"=>153 );

print_r($myBlue->makeGradient());
// array( "light"=>"8cb3d9" ,"dark"=>"336699" )

Static Methods

  • hslToHex( $hsl ) : Convert a HSL array to a HEX string.
  • hexToHsl( $hex ) : Convert a HEX string into an HSL array.
  • hexToRgb( $hex ) : Convert a HEX string into an RGB array.
  • rgbToHex( $rgb ) : Convert an RGB array into a HEX string.
/**
 * On The Fly Custom Calculations
 */

use Mexitek\PHPColors\Color;

 // Convert my HEX
 $myBlue = Color::hexToHsl("#336699");

 // Get crazy with the HUE
 $myBlue["H"] = 295;

 // Gimme my new color!!
 echo Color::hslToHex($myBlue);
 // 913399

CSS Helpers

  • getCssGradient( [$amount] [, $vintageBrowsers] ) : Generates the CSS3 gradients for safari, chrome, opera, firefox and IE10. Optional percentage amount for lighter/darker shade. Optional boolean for older gradient CSS support.

Would like to add support to custom gradient stops

use Mexitek\PHPColors\Color;

// Initialize my color
$myBlue = new Color("#336699");

// Get CSS
echo $myBlue->getCssGradient();
/* - Actual output doesn't have comments and is single line

  // fallback background
  background: #336699;

  // IE Browsers
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#8cb3d9', endColorstr='#336699'); 
 
  // Safari 5.1+, Mobile Safari, Chrome 10+
  background-image: -webkit-linear-gradient(top, #8cb3d9, #336699);

  // Standards
  background-image: linear-gradient(to bottom, #8cb3d9, #336699);

*/

However, if you want to support the ancient browsers (which has negligible market share and almost died out), you can set the second parameter to TRUE. This will output:

use Mexitek\PHPColors\Color;
$myBlue = new Color("#336699");

// Get CSS
echo $myBlue->getCssGradient(10, TRUE);
/* - Actual output doesn't have comments and is single line
  
  background: #336699; // fallback background
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#8cb3d9', endColorstr='#336699'); // IE Browsers
  background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#8cb3d9), to(#336699)); // Safari 4+, Chrome 1-9
  background-image: -webkit-linear-gradient(top, #8cb3d9, #336699); // Safari 5.1+, Mobile Safari, Chrome 10+
  background-image: -moz-linear-gradient(top, #8cb3d9, #336699); // Firefox 3.6+
  background-image: -o-linear-gradient(top, #8cb3d9, #336699); // Opera 11.10+
  background-image: linear-gradient(to bottom, #8cb3d9, #336699); // Standards

*/

Github Contributors

  • mexitek
  • danielpataki
  • alexmglover
  • intuxicated
  • pborreli
  • curtisgibby
  • matthewpatterson
  • there4
  • alex-humphreys
  • zaher
  • primozcigler
  • thedavidmeister
  • tylercd100

phpcolors's People

Contributors

alex-humphreys avatar alexmglover avatar atmattpatt avatar bigjuevos avatar chemix avatar curtisgibby avatar intuxicated avatar jleagle avatar m-e-h avatar mexitek avatar mikehayesuk avatar pborreli avatar primozcigler avatar sgtlambda avatar sqsinger1123 avatar strarsis avatar thedavidmeister avatar thekayani avatar tylercd100 avatar zaher avatar

Watchers

 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.