Skip to content

ottawadeveloper/coloranalyzer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Color Analyzer

This project provides tools to analyze colors from CSS code to see which combinations comply with the W3C's recommended contrast ratio.

As this is a personal project, I've taken the opportunity to make some elements very robust (far robust than they probably need to be) so that it is very extendable by other solutions.

Color Support

Out of the box, this library provides support for:

  • 2-digit hex codes that represent a shade of grey
  • 3-digit hex codes that represent a web-safe color
  • 6-digit hex code colors
  • 8-digit hex codes that represent a color with alpha value
  • Official CSS color keywords
  • Valid calls to rgb(), rgba(), hsl() and hsla()

Other applications who leverage this library can extend the default supported methods by providing an object that implements the ColorProcessor interface and adding it to the ColorFactory.

Reporting Support

Out of the box, this library provides a reporting functionality that allows other applications to define the columns they want to see in a report, as well as a separate formatter. Reports are generated by pairing each color provided with each other color, and then running the report components for each pair. Out of the box, the following columns are supported:

  • ColorTextReport: Display the name of the color, using an instance of ColorProcessor to display the color. Note that you have to add it twice to the report: once for the foreground, and once for the background.
  • LuminosityContrastReport: Display the luminosity constrast ratio (value between 1 and 21) between the two colors.
  • Wcag2ComplianceReport: Displays whether the colors are compliant with either the AA criteria or AAA criteria.

You can add your own reporting columns by implementing the ReportComponent interface and adding an instance of it to your report.

Blending Support

This library provides support for blending two colors together, and allowing other applications to choose the strategy. By default, the alpha composite method is used (with support for transparent backgrounds as well). Blending is automatically applied to non-opaque colors when calculating the luminosity contrast.

To change the blending strategy, you can implement the ColorBlender interface, and then pass the implementation to the ColorFactory. Only one blending strategy can be used.

Usage

See example-report.php for an example of generating a report.

License

This project is provided under the MIT license, meaning that you can reuse it as you would like, as long as you keep the LICENSE.txt file with it.

About

Composer library for color parsing and analysis for WCAG purposes.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages