ColorJizz is a PHP library for manipulating and converting colors.

Overview

#Getting started:

ColorJizz-PHP uses the PSR-0 standards for namespaces, so there should be no trouble using with frameworks like Symfony 2.

###Autoloading

An autoloader class is provided for when loading ColorJizz yourself.

First, include the autoloader and call the static register() function.

<?php
require_once 'path/to/colorjizz/lib/MischiefCollective/ColorJizz/Autoloader.php';
MischiefCollective\ColorJizz\Autoloader::register();
?>

Now all ColorJizz classes will be automatically loaded in.

###Converting between formats

ColorJizz can convert to and from any of the supported color formats:

<?php
use MischiefCollective\ColorJizz\Formats\Hex;

$red_hex = new Hex(0xFF0000);
$red_cmyk = $hex->toCMYK();

echo get_class($red_cmyk); // MischiefCollective\ColorJizz\Formats\CMYK
echo $red_cmyk; // 0,1,1,0
?>

Any color manipulation or conversion will return a new instance of a color class, therefore your original color objects remains intact.

Color manipulation can be chained together:

<?php
use MischiefCollective\ColorJizz\Formats\Hex;

echo Hex::fromString('red')->hue(-20)->greyscale(); // 555555
?>

Any color manipulation will always return the color in the same format unless you're specifically converting the format. For example:

<?php
use MischiefCollective\ColorJizz\Formats\RGB;

$red = new RGB(255, 0, 0);
echo get_class($red->hue(-20)->saturation(2)); // MischiefCollective\ColorJizz\Formats\RGB
?>

###Supported formats:

<?php
new RGB(r, g, b);
new CMY(c, m, y);
new CMYK(c, m, y, k);
new Hex(0x000000);
new HSV(h, s, v);
new CIELab(l, a, b);
new CIELCh(l, c, h);
new XYZ(x, y, z);
new Yxy(Y, x, y);

###Conversion functions:

<?php
->toRGB();
->toCMY();
->toCMYK();
->toHex();
->toHSV();
->toCIELab();
->toCIELCh();
->toXYZ();
->toYxy();
Comments
  • Change library name

    Change library name

    I don't care how great your library is, it won't get used in any kind of professional project with an offensive name like this. You may think you're clever, but the reality is that your attempt at humor is childish.

    opened by ebeyrent 2
  • HSL format

    HSL format

    Most lighten/darken functions expect a high lightness to approach white. HSL color format makes this easier than it would be using HSV (where a high value simply approaches a more pure color).

    opened by drake-p 0
  • renames toString() method because other colour classes also use __toString()

    renames toString() method because other colour classes also use __toString()

    renames toString() method because other colour classes also use __toString()

    actually I'd suggest renaming all __toString() methods to toString() because it's a public method

    opened by vredeling 0
  • Slow Distance Calculations

    Slow Distance Calculations

    When calculating the distance between colors it converts it's type. This isn't a huge issue unless you are checking a lot of distances. For instance I'm checking every pixel in a 570x570 picture against a list of 17 colors for the closest match, which is near 5.5 million comparisons.

    As a "quick cheat" I converted my 17 colors from their original Hex class to the CIELab class, but now my code knows about the internals of ColorJizz. I'm also only checking about 30% of the pixels, but that's unrelated.

    My thoughts was a dynamic class conversion. Instead of having a class for each file type we extend ColorJizz to hold all necessary information including $type (rgb, cmyk, etc), and a $values array. The key in the array is the type, and the values are the values typically stored in the class.

    We also have a generic convertor class, It'll likely have a "generic" type. Each color type will need to have 3 methods in this class such as GenericToRGB(), RGBToGeneric(), and validRGB().

    I'd have the performance gain without my code knowing about ColorJizz internals, and we'd also be creating a lot less objects since we could just change the $type and return $this;.

    I'd be happy to help, but would need some type of approval before doing such a drastic rewrite.

    opened by bayleedev 0
  • Slow Distance Calculations

    Slow Distance Calculations

    When calculating the distance between colors it converts it's type. This isn't a huge issue unless you are checking a lot of distances. For instance I'm checking every pixel in a 570x570 picture against a list of 17 colors for the closest match, which is near 5.5 million comparisons.

    As a "quick cheat" I converted my 17 colors from their original Hex class to the CIELab class, but now my code knows about the internals of ColorJizz. I'm also only checking about 30% of the pixels, but that's unrelated.

    My thoughts was a dynamic class conversion. Instead of having a class for each file type we extend ColorJizz to hold all necessary information including $type (rgb, cmyk, etc), and a $values array. The key in the array is the type, and the values are the values typically stored in the class.

    We also have a generic convertor class, It'll likely have a "generic" type. Each color type will need to have 3 methods in this class such as GenericToRGB(), RGBToGeneric(), and validRGB().

    I'd have the performance gain without my code knowing about ColorJizz internals, and we'd also be creating a lot less objects since we could just change the $type and return $this;.

    I'd be happy to help, but would need some type of approval before doing such a drastic rewrite.

    opened by bayleedev 0
  • Added autoloader psr-0 definition to composer package

    Added autoloader psr-0 definition to composer package

    added the extra bit to the package definition for generating the autoloader inside composer.

    Needs registering on packagist if you want to be able to require it in other projects without a custom repository specification.

    opened by ReactiveRaven 0
  • Add version tags for composer

    Add version tags for composer

    Please add a version tag to the repository. That would allow us to require that specific version in composer. Right now we are forced to use dev-master.

    opened by davidgorges 5
  • HEX to CMYK fail to convert

    HEX to CMYK fail to convert

    Hi, I'm wondering why the CMYK converter doesn't work? In your demo you are converting #ff0000 to CMYK, which translates to 0,1,1,0 – it should be more like 0,95,92,0. So is this a bug or do I need some libraries on my server?

    opened by cphilippsen 0
Owner
Mikeemoo
Mikeemoo
PHP library to detect and manipulate indentation of strings and files

indentation PHP library to detect and manipulate the indentation of files and strings Installation composer require --dev colinodell/indentation Usage

Colin O'Dell 34 Nov 28, 2022
The Universal Device Detection library will parse any User Agent and detect the browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), brand and model.

DeviceDetector Code Status Description The Universal Device Detection library that parses User Agents and detects devices (desktop, tablet, mobile, tv

Matomo Analytics 2.4k Jan 5, 2023
A fast PHP slug generator and transliteration library that converts non-ascii characters for use in URLs.

URLify for PHP A fast PHP slug generator and transliteration library, started as a PHP port of URLify.js from the Django project. Handles symbols from

Aband*nthecar 667 Dec 20, 2022
Library for free use Google Translator. With attempts connecting on failure and array support.

GoogleTranslateForFree Packagist: https://packagist.org/packages/dejurin/php-google-translate-for-free Library for free use Google Translator. With at

Yurii De 122 Dec 23, 2022
A PHP library for generating universally unique identifiers (UUIDs).

ramsey/uuid A PHP library for generating and working with UUIDs. ramsey/uuid is a PHP library for generating and working with universally unique ident

Ben Ramsey 11.9k Jan 8, 2023
A PHP string manipulation library with multibyte support

A PHP string manipulation library with multibyte support. Compatible with PHP 5.4+, PHP 7+, and HHVM. s('string')->toTitleCase()->ensureRight('y') ==

Daniel St. Jules 2.5k Jan 3, 2023
🉑 Portable UTF-8 library - performance optimized (unicode) string functions for php.

?? Portable UTF-8 Description It is written in PHP (PHP 7+) and can work without "mbstring", "iconv" or any other extra encoding php-extension on your

Lars Moelleken 474 Dec 22, 2022
🔡 Portable ASCII library - performance optimized (ascii) string functions for php.

?? Portable ASCII Description It is written in PHP (PHP 7+) and can work without "mbstring", "iconv" or any other extra encoding php-extension on your

Lars Moelleken 380 Jan 6, 2023
PHP library to parse urls from string input

Url highlight - PHP library to parse URLs from string input. Works with complex URLs, edge cases and encoded input. Features: Replace URLs in string b

Volodymyr Stelmakh 77 Sep 16, 2022
:accept: Stringy - A PHP string manipulation library with multibyte support, performance optimized

?? Stringy A PHP string manipulation library with multibyte support. Compatible with PHP 7+ 100% compatible with the original "Stringy" library, but t

Lars Moelleken 144 Dec 12, 2022
A language detection library for PHP. Detects the language from a given text string.

language-detection Build Status Code Coverage Version Total Downloads Minimum PHP Version License This library can detect the language of a given text

Patrick Schur 738 Dec 28, 2022
Text - Simple 1 Class Text Manipulation Library

Text - Simple 1 Class Text Manipulation Library Do you remember PHP's string functions? If not, just wrap you text with Text! It will save a minute on

Kazuyuki Hayashi 51 Nov 16, 2021
The Hoa\Ustring library.

Hoa is a modular, extensible and structured set of PHP libraries. Moreover, Hoa aims at being a bridge between industrial and research worlds. Hoa\Ust

Hoa 402 Jan 4, 2023
PCRE wrapping library that offers type-safe preg_* replacements.

composer/pcre PCRE wrapping library that offers type-safe preg_* replacements. If you are using a modern PHP version you are probably better off using

Composer 308 Dec 30, 2022
Extensive, portable and performant handling of UTF-8 and grapheme clusters for PHP

Patchwork UTF-8 for PHP Patchwork UTF-8 gives PHP developpers extensive, portable and performant handling of UTF-8 and grapheme clusters. It provides

Nicolas Grekas 80 Sep 28, 2022
php-crossplane - Reliable and fast NGINX configuration file parser and builder

php-crossplane Reliable and fast NGINX configuration file parser and builder ℹī¸ This is a PHP port of the Nginx Python crossplane package which can be

null 19 Jun 30, 2022
A tiny PHP class-based program to analyze an input file and extract all of that words and detect how many times every word is repeated

A tiny PHP class-based program to analyze an input file and extract all of that words and detect how many times every word is repeated

Max Base 4 Feb 22, 2022
A PHP class which allows the decoding and encoding of a wider variety of characters compared to the standard htmlentities and html_entity_decode functions.

The ability to encode and decode a certain set of characters called 'Html Entities' has existed since PHP4. Amongst the vast number of functions built into PHP, there are 4 nearly identical functions that are used to encode and decode html entities; despite their similarities, however, 2 of them do provide additional capabilities not available to the others.

Gavin G Gordon (Markowski) 2 Nov 12, 2022
Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way.

String Component The String component provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a un

Symfony 1.3k Dec 29, 2022