Repository navigation
Iris 5.0.0 fixes the PHP 8.5 deprecations, fixes a set of long-standing bugs, reads modern CSS color syntax, and adds alpha to OKLCH.
It is a major release, please read Breaking changes before you upgrade.
Requirements
- PHP 8.4 or later. Projects on older PHP versions stay on 4.x.
Highlights
- No more PHP 8.5 deprecations:
Non-canonical cast (double)inRgbaandHslais fixed. (#54) - CSS Color Level 4 syntax for all color functions:
Factory::init('rgb(10 20 30 / 50%)'); // Rgba Factory::init('hsl(0.5turn 50% 50% / .3)'); // Hsla Factory::init('oklch(62.8% 0.2577 29.23 / 0.5)'); Factory::init('#f0f8'); // Hexa Factory::init('transparent'); // Rgba
- WCAG contrast:
luminance(),contrast($background),isReadable($background)andmostReadable()pick an accessible text color. - Color difference:
distance($other)(deltaE OK) andequals($other, $tolerance)compare colors in any model. - Helpers:
toName(),invert(),complement(),json_encode()support, andFactory::tryInit()/Factory::isValid(). - Alpha for OKLCH:
oklch(... / 0.5)keeps the alpha through conversions and operations. - Operations keep the alpha:
lighten(),spin(),mix(),gradient()and the others no longer drop the alpha ofRgba,Hsla,HexaandOklch. - Safer API: operations return a new color and never change the original, setters clamp out-of-range values, and the whole library passes PHPStan at the max level.
Breaking changes
- Minimum PHP version is 8.4. The development dependencies are PHPUnit ^13.4 and PHPStan ^2.3.
- Manipulations and conversions return a new object; before, some manipulations changed the original object, and
toHex()on aHex(and so on) returned the object itself. - Setters clamp out-of-range values (
red(300)sets 255) and the hue wraps around 360 (hue(400)sets 40); a value that is not a number is ignored and the setter returns the color.Hex/Hexasetters take hex digits, as before. - Blending a color with alpha onto its background rounds each channel instead of rounding down, so some results are 1 higher (
rgba(0,0,0,0.3)givesrgb(179,179,179)). mix(),tint(),shade()andgradient()mix the alpha and weight the channels by alpha, like less.js and Sass.fade(),fadeIn()andfadeOut()returnHexaforHex/HexaandOklchforOklch(before:Rgba).Oklchkeeps the alpha ofoklch(... / a), so conversions to opaque models blend it onto white;Oklch::values()includes the alpha; a lightness without%that is not greater than 1 is a fraction (oklch(0.7 0.1 120)is 70%).- Conversions to HSV and CMYK keep one decimal, e.g.
hsv(303.5,96.7%,96.5%);Hsv::value()returns a float. Factory::init()throwsInvalidColorExceptionfor an empty string and unsupported functions (e.g.hwb()), and reads 4 hex digits only with a#.- For subclasses:
Hex/Hexause the newHexTrait,Rgb/RgbauseRgbTraitwithintchannels,$castsIntegerand some protected helpers are removed,BaseColorhas new protected methods, and the method signatures have native types.
The README has an Upgrading from 4.x section, and CHANGELOG.md has the full list.
Fixed
Rgbasetters read integers as hex:red(100)was ignored andred(5)set 55.spin()triggered "Implicit conversion from float to int" deprecations and lost the hue decimals.Factory::init()could not read space-separatedoklch(), also not the output ofOklch::__toString().- Round trips through HSV changed colors by up to 5 units.
fade()onHslareturnedRgba;gradient()crashed on an empty array and lost colors with few steps.- The parser could not read very small values in the form that PHP prints them (
1.0E-5), so some operations threw an exception. - Malformed strings such as
##fffandhsl(120,1%00,50)were accepted. - Color names in
Hsl,Hsla,HsvandCmykwere up to 2 units wrong (new Hsl('coral')gave#ff8052). spin(0),lighten(0)and other operations with 0 changedHsv,CmykandOklchcolors.
Full changelog: https://github.com/ozdemirburak/iris/blob/5.0.0/CHANGELOG.md