PHP code example of delfimov / gdimage

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

    

delfimov / gdimage example snippets


// initialize GDImage
$image = new GDImage('path/to/image.jpg');
 
// set fill color for empty image areas
$image->setFillColor([255, 0, 0]);

// Resize image. By default images are resized proportional and are not cropped,  
// with empty areas filled with color specified in setFillColor() method
$image->resize(1280, 720);

/* Add text to image 
The first parameter is text to add, 
the second parameter is optional, by default equals to: 
[
    'size' => 20,
    'angle' => 0,
    'x' => 0,
    'y' => 0,
    'color' => [0, 0, 0],
    'font' => '/../fonts/Roboto-Medium.ttf'
] 
*/
$image->addText(
    'Sample text to add',
    [
        'font' => __DIR__ . '/../fonts/Roboto-Medium.ttf',
        'size' => 18,
        'x' => 150,
        'y' => 100,
        'color' => [255, 0, 0]
    ]
);

// Save image
$image->save('path/to/newimage.jpg');