PHP code example of randomhost / image

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

    

randomhost / image example snippets



namespace randomhost\Image;

::getInstanceByPath('image.png');

// load overlay image
$overlay = Image::getInstanceByPath('overlay.png');

// insert overlay image on top of base image at x 15, y 20
$image->merge($overlay, 15, 20);

// set up a red text overlay
$text = new Text\Generic($image);
$text
    ->setTextFont('vera.ttf')
    ->setTextSize(12)
    ->setTextColor(
        new Color(
            0xFF,
            0x00,
            0x00
        )
    );

// set up a white border for the previously defined text overlay
$text = new Text\Decorator\Border($text);
$text->setBorderColor(
    new Color(
        0xFF,
        0xFF,
        0xFF
    )
);

// render text overlay onto the image at x 20, y 10
$text->insertText(
    20,
    10,
    'Example text'
);

// render the image
$image->render();