Passed
Branch main (03e511)
by smiley
11:51
created

imagetiler.php$0 ➔ log()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 3
dl 0
loc 2
rs 10
1
<?php
2
/**
3
 * @filesource   imagetiler.php
4
 * @created      20.06.2018
5
 * @author       smiley <[email protected]>
6
 * @copyright    2018 smiley
7
 * @license      MIT
8
 */
9
10
namespace chillerlan\ImagetilerExamples;
11
12
use chillerlan\Imagetiler\{Imagetiler, ImagetilerException, ImagetilerOptions};
13
use ImageOptimizer\OptimizerFactory;
14
use Psr\Log\AbstractLogger;
15
16
require_once __DIR__.'/../vendor/autoload.php';
17
18
$input = __DIR__.'/[YOUR HUGE IMAGE].png';
19
$utils = __DIR__.'/path/to/utils/%s[.exe]';
20
21
$options = [
22
	// ImagetilerOptions
23
	'zoom_min'             => 0,
24
	'zoom_max'             => 8,
25
	'zoom_normalize'       => 7,
26
	'tms'                  => false,
27
	'fill_color'           => '#000000',
28
	'fast_resize'          => false,
29
	'overwrite_tile_image' => true,
30
	'clean_up'             => false,
31
	'optimize_output'      => true,
32
	'memory_limit'         => '8G',
33
	'tile_format'          => 'jpeg',
34
#	'overwrite_base_image' => true,
35
	'no_temp_baseimages'   => true,
36
	'resize_blur_upsample' => 0.7,
37
	'resize_blur_downsample' => 0.7,
38
];
39
40
$optimizer_settings = [
41
	'execute_only_first_png_optimizer' => false,
42
	'advpng_bin'    => sprintf($utils, 'advpng'),
43
	'optipng_bin'   => sprintf($utils, 'optipng'),
44
	'pngcrush_bin'  => sprintf($utils, 'pngcrush'),
45
	'pngquant_bin'  => sprintf($utils, 'pngquant'),
46
	'execute_only_first_jpeg_optimizer' => false,
47
	'jpegoptim_bin' => sprintf($utils, 'jpegoptim'),
48
	'jpegtran_bin'  => sprintf($utils, 'jpegtran'),
49
];
50
51
$options = new ImagetilerOptions($options);
52
53
$logger = new class() extends AbstractLogger{
54
	public function log($level, $message, array $context = []){
55
		echo sprintf('[%s][%s] %s', date('Y-m-d H:i:s'), substr($level, 0, 4), trim($message))."\n";
56
	}
57
};
58
59
$optimizer = (new OptimizerFactory($optimizer_settings, $logger))->get($options->tile_format);
60
$tiler     = new Imagetiler($options, $optimizer, $logger);
61
62
try{
63
	$tiler->process($input, __DIR__.'/tiles');
64
}
65
catch(ImagetilerException $e){
66
	$logger->error($e->getMessage());
67
	$logger->error($e->getTraceAsString());
68
}
69