PHP code example of wordpressvn / poster-editor

1. Go to this page and download the library: Download wordpressvn/poster-editor 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/ */

    

wordpressvn / poster-editor example snippets


// Using composer
/  new PosterEditor\PosterEditor();
    $image->make('images/bridge.jpg')->fit(600, 600);
    $image->show();

} catch(Exception $e) {
    echo $e->getMessage();
}

$image = new PosterEditor\PosterEditor();
$image->make('images/bridge.jpg')->fit(1200, 630, 'bottom')->blackout(50);

$logo = new PosterEditor\PosterEditor();
$logo->make('images/logo.png')->downsize(150, null);

$image->insert($logo, array('x' => 50, 'y' => 50))->show();

$image = new PosterEditor\PosterEditor();
$image->make('images/bridge.jpg')->fit(1200, 630);
$image->grayscale()->brightness(-40);

$image->text(
    'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat Lorem ipsum dolor sit amet', // phpcs:ignore
    array(
        'x'          => 100,
        'y'          => 100,
        'width'      => 1000,                 
        'height'     => 400,                  
        'horizontal' => 'center',             
        'vertical'   => 'center',             
        'fontpath'   => 'fonts/opensans.ttf',
        'fontsize'   => 24,
        'lineheight' => 1.75,
        'color'      => '#ffffff',
        'opacity'    => 0,
        'debug'      => true,
    )
);

$image->show('jpg', 70);

$image = new PosterEditor\PosterEditor();
$image->make('images/bridge.jpg')->fit(900, 600);
$image->blackout(70);

$image->text(
    'Lorem ipsum dolor d d 4 g sit amet, consectetur adipiscing et, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex eas commodo consequat sdfsdfl', // phpcs:ignore
    array(
        'x'          => 100,
        'y'          => 100,
        'width'      => 600,                   
        'height'     => 400,                   
        'horizontal' => 'justify',             
        'vertical'   => 'justify',             
        'fontpath'   => 'fonts/opensans.ttf',
        'fontsize'   => 20,
        'lineheight' => 1.5,
        'color'      => '#ffffff',
        'opacity'    => 0,
        'debug'      => true,
    )
);

$image->show('png');

$image = new PosterEditor\PosterEditor();
$image->make('images/bridge.jpg')->crop(
    900, 600,
    array(
        'x' => '0',
        'y' => '100'
    )
);

$image->grayscale()->brightness(-40);

$image->text(
    'Large title with unknown height. Can be multi-line',
    array(
        'x'          => 50,
        'y'          => 100,
        'width'      => 800,
        'fontpath'   => '/fonts/merriweather.ttf',
        'fontsize'   => 48,
        'lineheight' => 1.5,
        'color'      => '#9999ff',
    ),
    $boundary
);

$image->text(
    'This text appears right after title using smart boundaries',
    array(
        'x'          => 50,
        'y'          => $boundary['y'] + $boundary['height'],
        'width'      => 800,
        'fontpath'   => '/fonts/opensans.ttf',
        'fontsize'   => 20,
        'lineheight' => 1.5,
        'color'      => '#ff9999',
    ),
    $boundary
);

$image->show();

$image = new PosterEditor\PosterEditor();
$image->make('images/bridge.jpg')->fit(1000, 630, 'bottom');
$image->contrast(5)->brightness(-30)->blur();

$image->rectangle(
    20, 20, 960, 590,
    array(
        'color'   => '#ffffff',
        'outline' => true,
        'width'   => 4,
    )
);

$image->ellipse(
    200, 200, 200, 200,
    array(
        'color'   => '#00ff00',
        'opacity' => 50,
    )
);

$image->ellipse(
    800, 200, 200, 200,
    array(
        'color'   => '#ff0000',
        'opacity' => 50,
    )
);

$image->rectangle(
    480, 280, 80, 140,
    array(
        'color'   => '#0000ff',
    )
);

$image->line(
    200, 500, 800, 500,
    array(
        'color'   => array(255, 255, 0),
        'opacity' => 10,
        'width'   => 4,
    )
);

$image->show('png');

$image->make(mixed $data)

$image->insert(mixed $data, array $options = array())

$image->canvas(int $width, int $height, array $options = array())

$image->crop(int $width, int $height, array $options = array())

$image->line(int $x1, int $y1, int $x2, int $y2, array $options = array())

$image->rectangle(int $x, int $y, int $width, int $height, array $options = array())

$image->ellipse(int $x, int $y, int $width, int $height, array $options = array())

$image->rotate(int $angle, array $options = array())

$image->text(string $text, array $options = array(), array &$boundary = array())