1. Go to this page and download the library: Download wyrihaximus/tile-stitcher 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/ */
wyrihaximus / tile-stitcher example snippets
declare(strict_types=1);
use Intervention\Image\Drivers\Gd\Driver;
use Intervention\Image\ImageManager;
use WyriHaximus\TileStitcher\Coordinate;
use WyriHaximus\TileStitcher\Dimensions;
use WyriHaximus\TileStitcher\FileLoader;
use WyriHaximus\TileStitcher\Stitcher;
use WyriHaximus\TileStitcher\Tile;
$tiles = [
new Tile(
new Coordinate(69, 69),
new FileLoader('map/69_69.png'),
),
new Tile(
new Coordinate(70, 69),
new FileLoader('map/70_69.png'),
),
];
$stitcher = new Stitcher(
new ImageManager(
new Driver(),
),
);
$image = $stitcher->stitch(
'image/png',
Map::calculate(
new Dimensions(512, 512),
...$tiles,
),
);
file_put_contents('output/two_tile.png', $image);
use React\Filesystem\Node\FileInterface;
use function React\Async\await;
final readonly class ReactFileLoader implements LoaderInterface
{
public function __construct(private FileInterface $file)
{
}
public function load(): string
{
return await($this->file->getContents());
}
}
use League\Flysystem\Filesystem;
final readonly class FLysystemFileLoader implements LoaderInterface
{
public function __construct(private Filesystem $filesystem, private string $path)
{
}
public function load(): string
{
return $this->filesystem->read($this->path);
}
}
$image = $stitcher->stitch(
'image/png',
Map::calculate(
new Dimensions(512, 512),
new CallalbleTileLocator(
'map/',
static function (string $fileName): Tile {
$fileNameWithoutExtension = str_replace('.png', '', basename($fileName));
$coords = explode('_', $fileNameWithoutExtension);
return new Tile(
new Coordinate(
...array_map('intval', $coords),
),
new FileLoader($fileName),
);
}
),
),
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.