PHP code example of tiross / imagecraft

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

    

tiross / imagecraft example snippets


use Imagecraft\ImageBuilder;

$options = ['engine' => 'php_gd'];
$builder = new ImageBuilder($options);
$context = $builder->about();
if (!$context->isEngineSupported()) {
    echo 'Sorry, image processing service is currently not available.'.PHP_EOL;
} else {
    $formats = $context->getSupportedImageFormatsToString();
    echo 'Make sure that you\'re using one of the following image formats: '.$formats.'.'.PHP_EOL;
    $formats = $context->getSupportedFontFormatsToString();
    echo 'We accept the following font formats: '.$formats.'.'.PHP_EOL;
}

use Imagecraft\ImageBuilder;

$options = ['engine' => 'php_gd', 'locale' => 'en'];
$builder = new ImageBuilder($options);
$image = $builder
    ->addBackgroundLayer()
        ->http('www.imagecraft.cc/web/images/pikachu.gif', 2048, 20)
        ->resize(400, 400, 'shrink')
        ->done()
    ->addImageLayer()
        ->filename(__DIR__.'/pikachu_what_to_do_logo_by_mnrart-d5h998b.png')
        ->move(-20, -20, 'bottom_right')
        ->done()
    ->save()
;
if ($image->isValid()) {
    file_put_contents(__DIR__.'/output.'.$image->getExtension(), $image->getContents());
} else {
    echo $image->getMessage().PHP_EOL;
}

use Imagecraft\ImageBuilder;

$options = ['engine' => 'php_gd', 'locale' => 'zh_TW'];
$builder = new ImageBuilder($options);

$layer = $builder->addBackgroundLayer();
$layer->filename(__DIR__.'/yotsuba_koiwai.gif');
$layer->resize(150, 150, 'fill_crop');

$layer = $builder->addTextLayer();
$layer->font(__DIR__.'/minecraftia.ttf', 12, '#FFF');
$layer->label(date('F j, Y, g:i a'));
$layer->move(-10, -10, 'bottom_right');

$image = $builder->save();
if ($image->isValid()) {
    file_put_contents(__DIR__.'/output.'.$image->getExtension(), $image->getContents());
} else {
    echo $image->getMessage().PHP_EOL;
}

use Imagecraft\ImageBuilder;

// Build an image

if ($image->isValid()) {
    file_put_contents(__DIR__.'/output.'.$image->getExtension(), $image->getContents());
    print_r($image->getExtras());
} else {
    echo $image->getMessage().PHP_EOL;
    print_r($image->getVerboseMessage());
}