Advance Usage

When setting multiple options to the QrCode instance, we have to remember that this class provides immutability. That is, every time we change an attribute it returns a cloned copy of the instance.

Immutability: The true constant is change. Mutation hides change. Hidden change manifests chaos. Therefore, the wise embrace history. Source - The Dao of Immutability

Remembering that fact, we can configure and use our instance like this:

// A label can be a string OR a Da\Contracts\LabelInterface instance. 
// Using the instance, we will have more control on how do we want the label to be displayed.
// Immutability also applies to this class! 
$label = (new Label('2amigos'))
    ->useFont(__DIR__ . '/../resources/fonts/monsterrat.otf')

$qrCode = (new QrCode(''))
    ->useLogo(__DIR__ . '/data/logo.png')
    ->useForegroundColor(51, 153, 255)
    ->useBackgroundColor(200, 220, 210)

$qrCode->writeFile(__DIR__ . '/codes/my-code.png');

© 2amigos 2013-2017