- Notifications
You must be signed in to change notification settings - Fork19
PHP library for color manipulation and conversion.
License
ozdemirburak/iris
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
PHP library for color manipulation and conversion.
For PHP 7.3 or PHP 7.4, use version ^2.5, and check thephp-7 branch.
Via Composer
$ composer require ozdemirburak/iris
useOzdemirBurak\Iris\Color\Hex;$hex =newHex('#ff00ff');// same as new Hex('fuchsia');echo$hex->red();// ffecho$hex->green();// 00echo$hex->blue();// ffecho$hex->values();// ['ff', '00', 'ff']$hexa =$hex->toHexa();// \OzdemirBurak\Iris\Color\Hexa('ff00ffff')$hsl =$hex->toHsl();// \OzdemirBurak\Iris\Color\Hsl('300,100,50')$hsla =$hex->toHsla();// \OzdemirBurak\Iris\Color\Hsla('300,100,50,1.0')$hsv =$hex->toHsv();// \OzdemirBurak\Iris\Color\Hsv('300,100,100')$rgb =$hex->toRgb();// \OzdemirBurak\Iris\Color\Rgb('255,0,255')$rgba =$hex->toRgba();// \OzdemirBurak\Iris\Color\Rgba('255,0,255,1.0')echo$hex;// #ff00ff
useOzdemirBurak\Iris\Color\Hexa;$hexa =newHexa('#ff00ff4c');echo$hexa->red();// ffecho$hexa->green();// 00echo$hexa->blue();// ffecho$hexa->alpha();// 0.3 - as a float for compatibility with the other conversionsecho$hexa->values();// ['ff', '00', 'ff', 0.3]$hsl =$hexa->toHsl();// \OzdemirBurak\Iris\Color\Hsl('300,100,50')$hsla =$hexa->toHsla();// \OzdemirBurak\Iris\Color\Hsla('300,100,50,0.3')$hsv =$hexa->toHsv();// \OzdemirBurak\Iris\Color\Hsv('300,100,100')$rgb =$hexa->toRgb();// \OzdemirBurak\Iris\Color\Rgb('255,0,255')$rgba =$hexa->toRgba();// \OzdemirBurak\Iris\Color\Rgba('255,0,255,0.3')echo$hexa;// #ff00ff4c
useOzdemirBurak\Iris\Color\Hsl;$hsl =newHsl('hsl(300,100%,50%)');// same as new Hsl('fuchsia');echo$hsl->hue();// 300echo$hsl->saturation();// 100echo$hsl->lightness();// 50$values =$hsl->values();// [300, '100%', '50%']$normalizedValues =$hsl->valuesInUnitInterval();// [300/360, 100/100, 50/100]$hex =$hsl->toHex();// \OzdemirBurak\Iris\Color\Hex('ff00ff')$hexa =$hsl->toHexa();// \OzdemirBurak\Iris\Color\Hexa('ff00ffff')$hsv =$hsl->toHsv();// \OzdemirBurak\Iris\Color\Hsv('300,100,100')$rgb =$hsl->toRgb();// \OzdemirBurak\Iris\Color\Rgb('255,0,255')$rgba =$hsl->toRgba();// \OzdemirBurak\Iris\Color\Rgba('255,0,255,1.0')echo$hsl;// hsl(300,100%,50%)
useOzdemirBurak\Iris\Color\Hsla;$hsla =newHsla('hsla(150,100%,50%,0.3)');echo$hsla->hue();// 150echo$hsla->saturation();// 100echo$hsla->lightness();// 50echo$hsla->alpha();// 0.3$values =$hsla->values();// [150, '100%', '50%', 0.3]$hex =$hsla->toHex();// \OzdemirBurak\Iris\Color\Hex('b2ffd8')$hex =$hsla->toRgba();// \OzdemirBurak\Iris\Color\Rgba('0,255,128,0.3')$hexa =$hsla->toHexa();// \OzdemirBurak\Iris\Color\Hexa('ff00ff4c')echo$hsla;// hsla(150,100%,50%,0.3)
useOzdemirBurak\Iris\Color\Hsv;$hsv =newHsv('hsv(300,100%,100%)');// same as new Hsv('fuchsia');echo$hsv->hue();// 300echo$hsv->saturation();// 100echo$hsv->value();// 100$values =$hsv->values();// [100, '100%', '100%']$normalizedValues =$hsv->valuesInUnitInterval();// [300/360, 100/100, 100/100]$hex =$hsv->toHex();// \OzdemirBurak\Iris\Color\Hex('ff00ff')$hexa =$hsv->toHexa();// \OzdemirBurak\Iris\Color\Hexa('ff00ffff')$hsl =$hsv->toHsl();// \OzdemirBurak\Iris\Color\Hsl('300,100,50')$hsla =$hsv->toHsla();// \OzdemirBurak\Iris\Color\Hsla('300,100,50,1.0')$hsv =$hsv->toHsv();// \OzdemirBurak\Iris\Color\Hsv('300,100,100')$rgb =$hsv->toRgb();// \OzdemirBurak\Iris\Color\Rgb('255,0,255')$rgba =$hsv->toRgba();// \OzdemirBurak\Iris\Color\Rgba('255,0,255,1.0')echo$hsv;// hsl(300,100%,100%)
useOzdemirBurak\Iris\Color\Rgb;$rgb =newRgb('rgb(255, 0, 255)');// same as new Rgb('fuchsia');echo$rgb->red();// 255echo$rgb->green();// 0echo$rgb->blue();// 255$values =$rgb->values();// [255, 0, 255]$hex =$rgb->toHex();// \OzdemirBurak\Iris\Color\Hex('ff00ff')$hexa =$rgb->toHexa();// \OzdemirBurak\Iris\Color\Hexa('ff00ffff')$hsl =$rgb->toHsl();// \OzdemirBurak\Iris\Color\Hsl('300,100,50')$hsla =$rgb->toHsla();// \OzdemirBurak\Iris\Color\Hsla('300,100,50,1.0')$hsv =$rgb->toHsv();// \OzdemirBurak\Iris\Color\Hsv('300,100,100')$rgb =$rgb->toRgb();// \OzdemirBurak\Iris\Color\Rgb('255,0,255')$rgba =$rgb->toRgba();// \OzdemirBurak\Iris\Color\Rgba('255,0,255,1.0')echo$rgb;// rgb(255,0,255)
useOzdemirBurak\Iris\Color\Rgba;$rgba =newRgba('rgba(93,111,222,0.33)');echo$rgba->red();// 93echo$rgba->green();// 111echo$rgba->blue();// 222echo$rgba->alpha();// 0.33,$hex =$rgba->background((newHex('ccc'))->toRgb())->toHex();// \OzdemirBurak\Iris\Color\Hex('a7add1')$hexa =$rgba->toHexa();// \OzdemirBurak\Iris\Color\Hexa('a7add154')echo$rgba;// rgba(127,127,127,0.5)
useOzdemirBurak\Iris\Color\Cmyk;$cmyk =newCmyk('cmyk(0,100,0,0)');echo$cmyk->cyan();// 0echo$cmyk->magenta();// 100echo$cmyk->yellow();// 0echo$cmyk->black();// 0$values =$cmyk->values();// [0, 100, 0, 0]$hex =$cmyk->toHex();// OzdemirBurak\Iris\Color\Hex('ff00ff')$hexa =$cmyk->toHexa();// OzdemirBurak\Iris\Color\Hexa('ff00ffff')$hsl =$cmyk->toHsl();// OzdemirBurak\Iris\Color\Hsl('300,100,50')$hsla =$cmyk->toHsla();// OzdemirBurak\Iris\Color\Hsla('300,100,50,1.0')$hsv =$cmyk->toHsv();// OzdemirBurak\Iris\Color\Hsv('300,100,100')$rgb =$cmyk->toRgb();// OzdemirBurak\Iris\Color\Rgb('255,0,255')$rgba =$cmyk->toRgba();// OzdemirBurak\Iris\Color\Rgba('255,0,255,1.0')echo$cmyk;// cmyk(0,100,0,0)
If you do not know what the color string will be (for example, you're getting it from a group of rows from a database),then you can try using Factory to instantiate an appropriate color class:
useOzdemirBurak\Iris\Color\Factory;$color = Factory::init('rgba(93,111,222,0.33)');echo$color->red();// 93echo$color->green();// 111echo$color->blue();// 222echo$color->alpha();// 0.33
You can clone a color object to make a copy and modify it as needed.
useOzdemirBurak\Iris\Color\Hex;$original =newHex('#b2b2b2');$cloned =$original->clone()->toHexa()->alpha(0.5);// OzdemirBurak\Iris\Color\Hexa('#b2b2b27f')
Saturate or desaturate by a percent.
echo (newHsl('90,80%,50%'))->saturate(20)->toHex();// #80ff00echo (newHsl('90, 80%, 50%'))->desaturate(20)->toRgb();// rgb(128,204,51)echo (newHex('#80cc33'))->grayscale();// #808080, same as desaturate 100
Lighten, darken or brighten by a percent.
$hex =newHex('#333');echo$hex->lighten(20);// #666666echo$hex->darken(20);// #000000echo$hex->brighten(20);// #666666
Spin by an angle [-360, 360]
$hex = (newHsl('10,90%,50'))->spin(30)->toHex();echo$hex;// #f2a60d
Mix by a percent.
$hex =newHex('#000');echo$hex->mix(newHex('#fff'),50);// #808080
Mix color with white by a percent.
$hex =newHex('#000');echo$hex->tint(50);// #808080
Mix color with black by a percent.
$hex =newHex('#FFF');echo$hex->shade(50);// #808080
Set the absolute opacity of a color by a percent.
$hsl =newHsl('90,90,50');echo$hsl->fade(10);// hsla(90,90%,50%,0.1)$rgb =newRgb('128,242,13');echo$rgb->fade(10);// rgba(128,242,13,0.1)
Increase the opacity of a color by a percent.
$hsla =newHsla('90,90,50,0.3');echo$hsla->fadeIn(10);// hsla(90,90%,50%,0.4)$rgba =newRgba('128,242,13,0.3');echo$rgba->fadeIn(10);// rgba(128,242,13,0.4)
Decrease the opacity of a color by a percent.
$hsla =newHsla('90,90,50,0.3');echo$hsla->fadeOut(10);// hsla(90,90%,50%,0.2)$rgba =newRgba('128,242,13,0.3');echo$rgba->fadeOut(10);// rgba(128,242,13,0.2)
Determine if color is dark or light color.
$hex =newHex('#000');echo$hex->isLight();// falseecho$hex->isDark();// true
Please seeCHANGELOG for more information what has changed recently.
$ composertest
Please seeCONTRIBUTING for details.
The MIT License (MIT). Please seeLicense File for more information.
About
PHP library for color manipulation and conversion.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors15
Uh oh!
There was an error while loading.Please reload this page.