Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

An image tile generator for PHP 7.4+

License

NotificationsYou must be signed in to change notification settings

chillerlan/php-imagetiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A script for PHP 7.4+ to cut images (maps) into pieces (tiles). Based on themap 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 SupportPackagist versionLicenseContinuous IntegrationCodeCovPackagist downloads

Documentation

Requirements

Installation

requirescomposer

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

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

Profit!

Usage

Use theexample for live testing.

// invoke an options instance$options =newImagetilerOptions(['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 = (newOptimizerFactory([]))->get();// invoke and run the tiler$tiler  =newImagetiler($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 thepolicy.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

methodreturndescription
__construct(ContainerInterface $options = null, LoggerInterface $logger = null)-seeSettingsContainerInterface andLoggerInterface. Invokes an emptyImagetilerOptions object and aPsr\NullLogger if the respective parameters aren't set.
setOptions(ContainerInterface $options)Imagetilerset options on-the-fly, called internally by the constructor
setOptimizer(Optimizer $optimizer)Imagetilerset an optimizer instance on-the-fly, called internally by the constructor
process(string $image_path, string $out_path)Imagetilerprocesses the given image from$image_path and dumps the output to$out_path

ImagetilerOptions properties

propertytypedefaultalloweddescription
$tile_sizeint256positive intwidth/height of a single tile
$zoom_minint0positive intminimum zoom level
$zoom_maxint8positive intmaximum zoom level
$zoom_normalizeintnullpositive intthis zoom level represents the size of the original image. zoom levels higher than this will be upscaled, which may take some time and resources depending on the size of the input image.
$tmsboolfalse*if set to true - the origin will be set to bottom left, +y upwards, according toTile Map Service Specification, otherwise the origin is on the top left, +y downwards, like described by theGoogle Maps specification
$fill_colorstring'#000000'*the fill color for leftover space, can be transparent for png
$memory_limitstring'-1'*seephp.ini settings
$store_structurestring'%1$d/%2$d/%3$d'*storage structure - can be anything. %1$d = zoom, %2$d = x, %3$d = y. seesprintf()
$fast_resize_upsampleboolfalse*determines whether to use fastImagick::scaleImage() (true) or slowImagick::resizeImage() (false)
$resize_filter_upsampleintImagick::FILTER_ROBIDOUXSHARPImagick::FILTER_*seeImagick::resizeImage() andImagick filter constants
$resize_blur_upsamplefloat1.0positive floatseeImagick::resizeImage()
$fast_resize_downsampleboolfalse*see$fast_resize_upsample
$resize_filter_downsampleintImagick::FILTER_LANCZOSRADIUSImagick::FILTER_*see$resize_filter_upsample
$resize_blur_downsamplefloat1.0positive floatsee$resize_blur_upsample
$tile_formatstring'png'png, jpgseeImagick formats
$tile_extstringnull*tile image extension - autodetected from format if none given.
$quality_jpegint800-100quality of the saved image in jpeg format
$imagick_tmpstringnull*ImageMagick tmp folder
$overwrite_base_imageboolfalse*
$overwrite_tile_imageboolfalse*
$clean_upbooltrue*whether or not to delete temp images
$optimize_outputboolfalse*enable image optimization (requiresOptimizer instance)
$no_temp_baseimagesboolfalse*whether or not to create and save temporary base images (may save resources)

[8]ページ先頭

©2009-2025 Movatter.jp