PHPackages                             dd/evolutioncms-snippets-ddcolortools - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. dd/evolutioncms-snippets-ddcolortools

ActiveModxevo-snippet[Utility &amp; Helpers](/categories/utility)

dd/evolutioncms-snippets-ddcolortools
=====================================

Converts the color to match the offset in tone, brightness, or saturation.

3.2.1(2y ago)02PHPPHP &gt;=5.6.0

Since May 8Pushed 1y ago2 watchersCompare

[ Source](https://github.com/DivanDesign/EvolutionCMS.snippets.ddColorTools)[ Packagist](https://packagist.org/packages/dd/evolutioncms-snippets-ddcolortools)[ Docs](https://code.divandesign.ru/modx/ddstartsnippet)[ RSS](/packages/dd-evolutioncms-snippets-ddcolortools/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (5)Dependencies (2)Versions (6)Used By (0)

(MODX)EvolutionCMS.snippets.ddColorTools
========================================

[](#modxevolutioncmssnippetsddcolortools)

Converts the color to match the offset in tone, brightness, or saturation.

Requires
--------

[](#requires)

- PHP &gt;= 5.6
- [(MODX)EvolutionCMS.libraries.ddTools](https://code.divandesign.ru/modx/ddtools) &gt;= 0.60
- [(MODX)EvolutionCMS.snippets.ddGetDocumentField](https://code.divandesign.ru/modx/ddgetdocumentfield) &gt;= 2.11.1

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

[](#installation)

### Manually

[](#manually)

#### 1. Elements → Snippets: Create a new snippet with the following data

[](#1-elements--snippets-create-a-new-snippet-with-the-following-data)

1. Snippet name: `ddColorTools`.
2. Description: `3.2.1 Converts the color to match the offset in tone, brightness, or saturation.`.
3. Category: `Core`.
4. Parse DocBlock: `no`.
5. Snippet code (php): Insert content of the `ddColorTools_snippet.php` file from the archive.

#### 2. Elements → Manage Files

[](#2-elements--manage-files)

1. Create a new folder `assets/snippets/ddColorTools/`.
2. Extract the archive to the folder (except `ddColorTools_snippet.php`).

### Using [(MODX)EvolutionCMS.libraries.ddInstaller](https://github.com/DivanDesign/EvolutionCMS.libraries.ddInstaller)

[](#using-modxevolutioncmslibrariesddinstaller)

Just run the following PHP code in your sources or [Console](https://github.com/vanchelo/MODX-Evolution-Ajax-Console):

```
//Include (MODX)EvolutionCMS.libraries.ddInstaller
require_once(
	$modx->getConfig('base_path') .
	'assets/libs/ddInstaller/require.php'
);

//Install (MODX)EvolutionCMS.snippets.ddColorTools
\DDInstaller::install([
	'url' => 'https://github.com/DivanDesign/EvolutionCMS.snippets.ddColorTools',
	'type' => 'snippet'
]);
```

- If `ddColorTools` is not exist on your site, `ddInstaller` will just install it.
- If `ddColorTools` is already exist on your site, `ddInstaller` will check it version and update it if needed.

Parameters description
----------------------

[](#parameters-description)

### Input color

[](#input-color)

- `inputColor`

    - Desctription: Input color as HEX, HSL or HSB/HSV, with or without alpha-channel.
        Case-insensitive.
        Valid format examples:
        - `ffffff`
        - `#FFFFFF`
        - `#FFFFFFFF`
        - `hsl(0, 0%, 100%)`
        - `hsla(0, 0%, 100%)`
        - `HSL(0, 0, 100)`
        - `hsb(0, 0%, 100%)`
        - `hsba(0, 0%, 100%)`
        - `hsv(0, 0%, 100%)`
        - `hsva(0, 0%, 100%)`
        - `hsb(0, 0, 100)`
        - `hsv(0, 0, 100)`
    - Valid values: `string`
    - **Required**
- `inputColor_docField`

    - Desctription: The name of the document field / TV which value is required to get.
        If the parameter is passed then the input string will be taken from the field / TV and `inputColor` will be ignored.
    - Valid values: `string`
    - Default value: —
- `inputColor_docId`

    - Desctription: ID of the document which field/TV value is required to get.
        `inputColor_docId` equals the current document id since `inputString_docId` is unset.
    - Valid values: `integer`
    - Default value: —

### Color modification

[](#color-modification)

All parameters can contain the following special operators:

1. `+` (e. g. `+10`) — plus
2. `-` (e. g. `-10`) — minus
3. `abs` — round to max or min value
4. `r` — invert
5. without operator (e. g. `10`) — just set equal to

- `offset_h`

    - Desctription: Operations of the hue offset separated by commas.
    - Valid values: `stringCommaSeparated`
    - Default value: `'+0'`
- `offset_h[i]`

    - Desctription: Offset of the hue in degrees (`[-360; +360]`).
    - Valid values: `string`
    - **Required**
- `offset_s`

    - Desctription: Operations of the saturation offset separated by commas.
    - Valid values: `stringCommaSeparated`
    - Default value: `'+0'`
- `offset_s[i]`

    - Desctription: Offset of the saturation in persents (`[-100; +100]`).
    - Valid values: `string`
    - **Required**
- `offset_l`

    - Desctription: Operations of the lightness offset separated by commas.
    - Valid values: `stringCommaSeparated`
    - Default value: `'+0'`
- `offset_l[i]`

    - Desctription: Offset of the lightness in persents (`[-100; +100]`).
    - Valid values: `string`
    - **Required**
- `offset_a`

    - Desctription: Operations of the alpha-channel offset separated by commas.
    - Valid values: `stringCommaSeparated`
    - Default value: `'+0'`
- `offset_a[i]`

    - Desctription: Offset of the alpha-channel in persents (`[-100; +100]`).
    - Valid values: `string`
    - **Required**

### Output

[](#output)

- `result_outputFormat`

    - Desctription: Output color format.
        Case-insensitive.
    - Valid values:
        - `'hex'`
        - `'hsl'`
        - `'rgb'`
    - Default value: `'hsl'`
- `result_tpl`

    - Desctription: Chunk to parse result.
        Available placeholders:
        - `[+ddResult+]` — full color string
        - `[+ddH+]` — hue
        - `[+ddS+]` — saturation
        - `[+ddL+]` — lightness
        - `[+ddA+]` — alpha-channel
        - `[+ddIsDark+]` — is color dark (`0` || `1`)?
    - Valid values:
        - `stringChunkName`
        - `string` — use inline templates starting with `@CODE:`
    - Default value: —
- `result_tpl_placeholders`

    - Desctription: Additional data has to be passed into the `result_tpl`.
        Nested objects and arrays are supported too:
        - `{"someOne": "1", "someTwo": "test" }` =&gt; `[+someOne+], [+someTwo+]`.
        - `{"some": {"a": "one", "b": "two"} }` =&gt; `[+some.a+]`, `[+some.b+]`.
        - `{"some": ["one", "two"] }` =&gt; `[+some.0+]`, `[+some.1+]`.
    - Valid values:
        - `stringJsonObject` — as [JSON](https://en.wikipedia.org/wiki/JSON)
        - `stringHjsonObject` — as [HJSON](https://hjson.github.io/)
        - `stringQueryFormatted` — as [Query string](https://en.wikipedia.org/wiki/Query_string)
        - It can also be set as a native PHP object or array (e. g. for calls through `$modx->runSnippet`):
            - `arrayAssociative`
            - `object`
    - Default value: —

Examples
--------

[](#examples)

### Set black or white font color depending on background color

[](#set-black-or-white-font-color-depending-on-background-color)

We need black texts in light backgrounds and vice versa.

Let's pass background color as `inputColor` to the snippet:

```
color: [[ddColorTools?
	&inputColor=`#007cc3`
	&result_tpl=`blackOrWhiteColor`
]];

```

Code of the `blackOrWhiteColor` chunk:

```
hsl(0, 0%, [[ddIf?
	&operand1=`[+ddIsDark+]`
	&operator=`bool`
	&trueChunk=`100`
	&falseChunk=`0`
]]%)

```

### Run the snippet through `\DDTools\Snippet::runSnippet` without DB and eval

[](#run-the-snippet-through-ddtoolssnippetrunsnippet-without-db-and-eval)

```
//Include (MODX)EvolutionCMS.libraries.ddTools
require_once(
	$modx->getConfig('base_path') .
	'assets/libs/ddTools/modx.ddtools.class.php'
);

//Run (MODX)EvolutionCMS.snippets.ddColorTools
\DDTools\Snippet::runSnippet([
	'name' => 'ddColorTools',
	'params' => [
		'inputColor' => '#000000',
		'result_tpl' => 'colorTpl'
	]
]);
```

Links
-----

[](#links)

- [Home page](https://code.divandesign.ru/modx/ddcolortools)
- [Telegram chat](https://t.me/dd_code)
- [Packagist](https://packagist.org/packages/dd/evolutioncms-snippets-ddcolortools)
- [GitHub](https://github.com/DivanDesign/EvolutionCMS.snippets.ddColorTools)

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance28

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~450 days

Total

4

Last Release

849d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/09b81986267e62b5fde1473b40aa6f11f7bc26c1c29d5f80f2768c8788e08110?d=identicon)[dd](/maintainers/dd)

---

Top Contributors

[![Ronef](https://avatars.githubusercontent.com/u/1333424?v=4)](https://github.com/Ronef "Ronef (66 commits)")

---

Tags

modxMODX Evoevoevolution-cmsmodx evolutionevo cmsevolutioncmsdivandesigndd studiodd groupddcolortoolscolor toolscolor converthsl convertrgb convertrgb to hslhsl to rgb

### Embed Badge

![Health badge](/badges/dd-evolutioncms-snippets-ddcolortools/health.svg)

```
[![Health](https://phpackages.com/badges/dd-evolutioncms-snippets-ddcolortools/health.svg)](https://phpackages.com/packages/dd-evolutioncms-snippets-ddcolortools)
```

PHPackages © 2026

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