Colors

IDML-Creator supports process colors, spot colors, and tint colors.

Process and Spot Colors

Set up a Color object and add it to the Content object like that:

<?php

use IDML\Content\Color\Color;

$myColor = new Color(); 

$content->addColor($myColor);

If you want to set your own unique identifier – which is recommended here –, set up the Color like that: new Color('UniqueName');

A color object can be set to styles an other elements, for example:

<?php 

$myParagraphStyle->setFillColor($myColor);

Setting the color value

The color value can be set by using the bitandblack/colors library. This library is required by default and provides a lot of color spaces. Supported color spaces are:

  • CIELab
  • CMY
  • CMYK
  • HEX
  • HKS
  • HSL
  • HSLA
  • PANTONE
  • RAL
  • RGB
  • RGBA
  • XYZ

So adding a color value works like that:

<?php

use Color\Value\CMYK;

$myColor->setColorValue(
    new CMYK(0, 100, 100, 0)
);

The color library provides also all color values of PANTONE, HKS and RAL, so it's worth having a look at it. More information about the color library is available under bitbucket.org/wirbelwild/colors.

Setting the color model

The color model can be set with the help of the Color Model Enum.

<?php

use IDML\Content\Enum\Color\Model;

/**
 * This will create a process color 
 */
$myColor->setModel(Model::PROCESS());

/**
 * This will create a spot color 
 */
$myColor->setModel(Model::SPOT());

Setting the color space

The color space can be set with the help of the Color Space Enum.

<?php

use IDML\Content\Enum\Color\Space;

/**
 * This will set the space to RGB 
 */
$myColor->setSpace(Space::RGB());

/**
 * This will set the space to CMYK 
 */
$myColor->setSpace(Space::CMYK());

/**
 * This will set the space to LAB 
 */
$myColor->setSpace(Space::LAB());

Hiding colors from the swatches panel

Per default, every color will be set to visible what means that it will become visible in the swatches panel. If you want to use a color without adding it to the swatches panel, set it to invisible:

<?php

$myColor->setVisible(false);

Tint Colors

Tint Colors are a percentual part of a process or spot color. You need a process or spot color to create a tint color.

Set up a Tint object and add it to the Content object like that:

<?php 

use IDML\Content\Color\Color;
use IDML\Content\Color\Tint;

$myColor = new Color('myColor'); 
$myTintColor = new Tint($myColor);

$content->addTint($myTintColor);

A tint color object can be set to style another element, for example:

<?php 

$myParagraphStyle->setFillColor($myTintColor);

Tint value

<?php 

/**
 * This will define a Tint Color with a value of 50% 
 */
$myTintColor->setTintValue(50);

Gradients

To create a gradient, there are at least two colors needed:

<?php 

use Color\Value\CMYK;
use IDML\Content\Color\Color;
use IDML\Content\Color\Tint;

$myFirstColor = new Color('My first color'); 
$myFirstColor->setColorValue(
    new CMYK(0, 100, 100, 0)
);

$mySecondColor = new Color('My second color'); 
$mySecondColor->setColorValue(
    new CMYK(100, 0, 50, 0)
);

Those colors can be added to a gradient object:

<?php

use IDML\Content\Color\Gradient;

$gradient = new Gradient();
$gradient
    ->addColor($myFirstColor)
    ->addColor($mySecondColor)
;

For sure, those colors and the gradient need to be added to the content object:

<?php 

$content->addColor($myFirstColor, $mySecondColor, $gradient);

The gradient can be used for example as background of a rectangle. The angle of the gradient can be defined there, too.

<?php

use IDML\Content\Rectangle;

$rectangle = new Rectangle();
$rectangle
    ->setFillColor($gradient)
    ->setGradientFillAngle(90)
;