PHP code example of darrynten / pslayers

1. Go to this page and download the library: Download darrynten/pslayers library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

darrynten / pslayers example snippets


$init = [
    'id' => 12,
    'width' => 100,
    'height' => 100,
];

$pslayers = new Pslayers($init);

// Bare minimum for a blank layer
$layerConfig = [
    'id' => 14,
    'width' => 100,
    'height' => 100,
];

$layer = new BlankLayer($layerConfig);

// getting
$width = $layer->width(); // $width = 100

// setting
$layer->width(200); // $width = 200

$layer->composite(Imagick::COMPOSITE_LIGHTEN);

// Make a layer
$layer = new BlankLayer($config);

// Add to your Pslayers object
$pslayer->layers->addLayerToCollection($layer);

// Add with foced z-index (destructive, see notes below)
$pslayer->layers->addLayerToCollection($layer, 2);

// Make a collection
$collection = new LayerCollection();

// Add a layer to a collection
$collection->addLayerToCollection($layer);

// Add a layer with a forced z index (destructive, see notes below)
$collection->addLayerToCollection($layer, 1);

$layer = new TextLayer($config);

$layer->text('text');
$layer->font('/path/to/font');
$layer->fontFamily('Times');
$layer->fontSize(16);
$layer->fontWeight(400);
$layer->fontStretch(\Imagick::STRETCH_ANY);
$layer->fontSize(\Imagick::STYLE_NORMAL);
$layer->underColour('#FFF');
$layer->fillColour('rgba(255, 128, 0, 0.5)');
$layer->fillOpacity(0.1);
$layer->strokeColour('hsl(200, 20, 50)');
$layer->strokeWidth(2);
$layer->strokeOpacity(1.0);

$layer = new GradientLayer($config);

$layer->startColour('#FFFFFF');
$layer->endColour('#000000');

$layer = new RadialGradientLayer($config);

$layer->startColour('#FFFFFF');
$layer->endColour('#000000');

$layer = new SolidLayer($config);

$layer->colour('#FFFFFF');

$layer = new PatternLayer($config);

$layer->pattern('bricks');
$layer->scale(2);
$layer->scaleFilter(Imagick::FILTER_BICUBIC);

$layer = new PlasmaLayer($config);

$layer = new GroupLayer($config);

$newTextLayer = new TextLayer($config);
$newGradientLayer = new GradientLayer($config);

$layer->group->addLayerToCollection($newGradientLayer, 1);
$layer->group->addLayerToCollection($newTextLayer, 2);

$layer->render();

$blurFilter = new BlurFilter([
    'id' => 'blur',
    'radius' => 5,                      // / optional
]);

$blankLayer = new BlankLayer([
    'id' => 'blank',
    'filters' => [
        $blurFilter,
        // You can combine filters
    ]
])

$filter = new StainedGlassFilter([
    'id' => 1,
    'kind' => 'random',
    'size' => 50,
    'offset' => 0,
    'ncolors' => 8,
    'bright' => 100,
    'ecolor' => 'black',
    'thick' => 0,
    'rseed' => rand(),
]);

// And then add to a layer

$plasmaLayer = new PlasmaLayer([
    'id' => 'master-layer-plasma-layer',
    'width' => $width,
    'height' => $height,
    'opacity' => 0.8,
    'positionX' => 0,
    'positionY' => 0,
    'composite' => Imagick::COMPOSITE_DARKEN,
    'filters' => [
        $stainedGlassFilter,
    ],
]);

$diceFilter = new DiceFilter([
    'id' => 'master-layer-dice-filter',
    'size' => 100,
    'percent' => 100,
    'center' => '10,10',
    'radii' => '0,0',
    'rounding' => '0,0',
]);

namespace DarrynTen\Pslayers\Filters\Filter\Fred\StainedGlass;

use DarrynTen\Pslayers\Filters\Filter\Fred\FredBaseFilter;

class StainedGlassFilter extends FredBaseFilter
{
    protected $command = 'stainedglass';

    protected $switchMap = [
        'kind' => 'k',
        'size' => 's',
        'offset' => 'o',
        'ncolors' => 'n',
        'bright' => 'b',
        'ecolor' => 'e',
        'thick' => 't',
        'rseed' => 'r',
    ];

    protected $kind;
    protected $size;
    protected $offset;
    protected $ncolors;
    protected $bright;
    protected $ecolor;
    protected $thick;
    protected $rseed;

    public function __construct(array $config)
    {
        // Do your validation here, before you construct the parent

        parent::__construct($config);
    }