PHP code example of np-shop / php-bgcode

1. Go to this page and download the library: Download np-shop/php-bgcode 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/ */

    

np-shop / php-bgcode example snippets


use NPShop\BgCode\BgCode;

$bgcode = BgCode::open('print.bgcode');

$bgcode = BgCode::open('print.bgcode');

$handle = fopen('print.bgcode', 'rb');
$bgcode = BgCode::fromStream($handle);

$header = $bgcode->header();

var_dump($header->magicString());
var_dump($header->version);
var_dump($header->checksumType);

foreach ($bgcode->blocks() as $block) {
    var_dump($block::class);
}

foreach ($bgcode->gcode() as $chunk) {
    file_put_contents('output.gcode', $chunk, FILE_APPEND);
}

$metadata = $bgcode->metadata();

foreach ($metadata as $class => $values) {
    var_dump($class, $values);
}

foreach ($bgcode->thumbnails() as $thumbnail) {
    var_dump($thumbnail->format(), $thumbnail->width(), $thumbnail->height());
}
bash
composer