PHPackages                             sevenecks/ansi - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. sevenecks/ansi

ActiveLibrary[CLI &amp; Console](/categories/cli)

sevenecks/ansi
==============

This package offers an API to colorize strings of text with various ANSI colors using static methods.

1.0.9(7y ago)16.4k↓25%4MITPHPPHP &gt;=5.4

Since Dec 8Pushed 7y ago1 watchersCompare

[ Source](https://github.com/SevenEcks/ansi)[ Packagist](https://packagist.org/packages/sevenecks/ansi)[ Docs](https://github.com/sevenecks)[ RSS](/packages/sevenecks-ansi/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (13)Used By (4)

Installation
------------

[](#installation)

```
composer require sevenecks/ansi
```

Colorize
--------

[](#colorize)

### Usage

[](#usage)

#### Static Usage

[](#static-usage)

The methods on Colorize can be called statically and the full API is listed later.

```
require_once __DIR__ . '/vendor/autoload.php';
use SevenEcks\Ansi\Colorize;

$test_string = 'This is a test';

echo Colorize::italic($test_string) . "\n";
echo Colorize::cyan($test_string) . "\n";
echo Colorize::bgRed($test_string) . "\n";
// background color first
echo Colorize::cyan(Colorize::bgRed($test_string)) . "\n";
// manually call the colorize string function
echo Colorize::colorizeString("TEST STRING", Colorize::$FOREGROUND_BLUE);
```

#### Instantiated Usage

[](#instantiated-usage)

Colorize also supports a magic method that will allow you to call the static methods dynamically, if you want to instantiate the Colorize class. This can be useful for dependency injection.

```
require_once __DIR__ . '/vendor/autoload.php';
use SevenEcks\Ansi\Colorize;

$test_string = 'This is a test';

$colorize = new Colorize;

echo $color->red('tester');
echo $color->darkGray('testy mctesterson');
```

### Colors

[](#colors)

There are several colors available for foreground and background.

#### Foreground

[](#foreground)

Colorize::italic Colorize::bold Colorize::underline Colorize::invert Colorize::darkGray Colorize::blue Colorize::lightBlue Colorize::green Colorize::lightGreen Colorize::cyan Colorize::lightCyan Colorize::red Colorize::lightRed Colorize::purple Colorize::lightPurple Colorize::brown Colorize::yellow Colorize::lightGray Colorize::white

#### Background

[](#background)

Colorize::bgBlack Colorize::bgRed Colorize::bgGreen Colorize::bgYellow Colorize::bgBlue Colorize::bgMagenta Colorize::bgCyan Colorize::bgLightGray

API
---

[](#api)

```
//foreground colors
public static $FOREGROUND_BLACK = '0;30';
public static $FOREGROUND_DARK_GRAY = '1;30';
public static $FOREGROUND_BLUE = '0;34';
public static $FOREGROUND_LIGHT_BLUE = '1;34';
public static $FOREGROUND_GREEN = '0;32';
public static $FOREGROUND_LIGHT_GREEN = '1;32';
public static $FOREGROUND_CYAN = '0;36';
public static $FOREGROUND_LIGHT_CYAN = '1;36';
public static $FOREGROUND_RED = '0;31';
public static $FOREGROUND_LIGHT_RED = '1;31';
public static $FOREGROUND_PURPLE = '0;35';
public static $FOREGROUND_LIGHT_PURPLE = '1;35';
public static $FOREGROUND_BROWN = '0;33';
public static $FOREGROUND_YELLOW = '1;33';
public static $FOREGROUND_LIGHT_GRAY = '0;37';
public static $FOREGROUND_WHITE = '1;37';
public static $FOREGROUND_BOLD = '1';
public static $FOREGROUND_UNDERLINE = '4';
public static $FOREGROUND_ITALIC = '3';
public static $FOREGROUND_INVERT = '7';
public static $FOREGROUND_STRIKEOUT = '9';

// background colors
public static $BACKGROUND_BLACK = '40';
public static $BACKGROUND_RED = '41';
public static $BACKGROUND_GREEN = '42';
public static $BACKGROUND_YELLOW = '43';
public static $BACKGROUND_BLUE = '44';
public static $BACKGROUND_MAGENTA = '45';
public static $BACKGROUND_CYAN = '46';
public static $BACKGROUND_LIGHT_GRAY = '47';

/**
 * Dynamically call the static methods from instance variables
 * and provide the correct arguments as needed
 *
 * @param string $name
 * @param array $arguments
 * @return string
 */
public function __call($name, $arguments)

/**
* Colorize a string of text and return it
*
* @param string $text
* @param string $color
*
* @return string
*/
public static function colorizeString($text, $color)

/**
 * strikethrough some text
 *
 * @param string $text
 * @return string
 */
public static function strikeout($text)

/**
 * invert the foreground of a string
 *
 * @param string $text
 * @return string
 */
public static function invert($text)

/**
 * bold the foreground of a string
 *
 * @param string $text
 * @return string
 */
public static function bold($text)

/**
 * Italic the foreground of a string
 *
 * @param string $text
 * @return string
 */
public static function italic($text)

/**
 * Underline the foreground of a string
 *
 * @param string $text
 * @return string
 */
public static function underline($text)

/**
* Colorize the foreground of a string
*
* @param string $text
* @return string
*/
public static function black($text)
public static function darkGray($text)
public static function blue($text)
public static function lightBlue($text)
public static function green($text)
public static function lightGreen($text)
public static function cyan($text)
public static function lightCyan($text)
public static function red($text)
public static function lightRed($text)
public static function purple($text)
public static function lightPurple($text)
public static function brown($text)
public static function yellow($text)
public static function lightGray($text)
public static function white($text)

/**
 * Colorize the background of a string
 *
 * @param string $text
 * @return string
 */
public static function bgBlack($text)
public static function bgRed($text)
public static function bgGreen($text)
public static function bgYellow($text)
public static function bgBlue($text)
public static function bgMagenta($text)
public static function bgCyan($text)
public static function bgLightGray($text)

## ColorInterface

You can use the ColorInterface.php file to implement your own ANSI Colorization class. The interface requires all the functions that the Colorize class implements, but does not care about how you define your colors or what is going on below the hood.
```

Change Log
----------

[](#change-log)

Please see [Change Log](CHANGELOG.md) for more information.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 82.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~25 days

Recently: every ~44 days

Total

12

Last Release

2806d ago

Major Versions

v0.1.0 → v1.0.02017-12-08

v0.1.1 → 1.0.12017-12-11

### Community

Maintainers

![](https://www.gravatar.com/avatar/963368d2aa1a4a1bf29571edf1377016ec16104a567abd89075b78f0edbf0925?d=identicon)[sevenecks](/maintainers/sevenecks)

---

Top Contributors

[![BrendanAlipes](https://avatars.githubusercontent.com/u/40271827?v=4)](https://github.com/BrendanAlipes "BrendanAlipes (19 commits)")[![sevenecks](https://avatars.githubusercontent.com/u/2490474?v=4)](https://github.com/sevenecks "sevenecks (4 commits)")

---

Tags

ansibashcolorsphpstaticcliconsoleshellcoloransicolors

### Embed Badge

![Health badge](/badges/sevenecks-ansi/health.svg)

```
[![Health](https://phpackages.com/badges/sevenecks-ansi/health.svg)](https://phpackages.com/packages/sevenecks-ansi)
```

###  Alternatives

[kevinlebrun/colors.php

Colors for PHP CLI scripts

3426.7M45](/packages/kevinlebrun-colorsphp)[alecrabbit/php-console-spinner

Extremely flexible spinner for \[async\] php cli applications

24032.0k2](/packages/alecrabbit-php-console-spinner)[alecrabbit/php-cli-snake

Lightweight cli spinner with zero dependencies

29211.3k5](/packages/alecrabbit-php-cli-snake)[maximebf/consolekit

Library to create command line utilities

114104.4k9](/packages/maximebf-consolekit)[inhere/console

php console library, provide console argument parse, console controller/command run, color style, user interactive, information show.

3477.4k12](/packages/inhere-console)[malenki/ansi

Simple class to put some colors into your CLI PHP apps!

4345.0k1](/packages/malenki-ansi)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
