chillerlan/php-imagetiler

3.2.0 2024-03-22 12:53 UTC

This package is auto-updated.

Last update: 2024-10-22 14:22:02 UTC


README

A script for PHP 7.4+ to cut images (maps) into pieces (tiles). Based on the map tiler script by Fedik. This script will keep the proportions of the input image and generate only necessary tiles - no need for square input files!

PHP Version Support Packagist version License Continuous Integration CodeCov Packagist downloads

Documentation

Requirements

Installation

requires composer

composer.json (note: replace dev-main with a version boundary)

{
	"require": {
		"php": "^7.4 || ^8.0",
		"ext-imagick": "*",
		"chillerlan/php-imagetiler": "dev-main"
	}
}

Profit!

Usage

Use the example for live testing.

// invoke an options instance
$options = new ImagetilerOptions([
	'zoom_min'             => 0,
	'zoom_max'             => 8,
	'zoom_normalize'       => 6,
	'fill_color'           => 'transparent',
	'fast_resize'          => true,
	'optimize_output'      => true,
	// ... whatever you need
]);

// see https://github.com/psliwa/image-optimizer#configuration
$optimizer = (new OptimizerFactory([]))->get();

// invoke and run the tiler
$tiler  = new Imagetiler($options, $optimizer);
$tiler->process('/path/to/image.png', '/path/to/output/');

That's it!

Memory trouble

If you're running into issues with ImageMagick complaining about not enough space on the cache path, you might want to check the policy.xml in the ImageMagick installation path (on Windows). For your consideration: an image of 49152x49152 will generate a cache file of ~28.5GB,

Image optimizers

API

Imagetiler public methods

ImagetilerOptions properties