4
* @author Keith Hughitt
6
if (Config::MOD_IMAGICK_ENABLED == true)
7
require('JP2Image.php');
9
require('JP2Image.Manual.php');
11
class Tile extends JP2Image {
18
public function __construct($id, $zoomLevel, $x, $y, $tileSize) {
19
$xRange = array("start" => $x, "end" => $x);
20
$yRange = array("start" => $y, "end" => $y);
22
parent::__construct($id, $zoomLevel, $xRange, $yRange, $tileSize);
34
$format = $this->getImageFormat();
36
// Filepaths (for intermediate pgm and final png/jpg image)
37
$tile = $this->getFilePath($format);
39
// If tile already exists in cache, use it
40
if (Config::ENABLE_CACHE) {
41
if (file_exists($tile)) {
42
$this->display($tile);
47
// If nothing useful is in the cache, create the tile from scratch
48
$im = $this->buildImage($tile);
54
$this->display($tile);
61
function getFilePath($format) {
63
$filepath = $this->cacheDir . $this->tileSize . "/";
64
if (!file_exists($filepath))
68
$year = substr($this->timestamp,0,4);
69
$month = substr($this->timestamp,5,2);
70
$day = substr($this->timestamp,8,2);
72
// Create necessary directories
73
$filepath .= $year . "/";
74
if (!file_exists($filepath)) {
76
chmod($filepath, 0777);
79
$filepath .= $month . "/";
80
if (!file_exists($filepath)) {
82
chmod($filepath, 0777);
85
$filepath .= $day . "/";
86
if (!file_exists($filepath)) {
88
chmod($filepath, 0777);
91
// Convert coordinates to strings
92
$xStr = "+" . str_pad($this->x, 2, '0', STR_PAD_LEFT);
93
if (substr($this->x,0,1) == "-")
94
$xStr = "-" . str_pad(substr($this->x, 1), 2, '0', STR_PAD_LEFT);
96
$yStr = "+" . str_pad($this->y, 2, '0', STR_PAD_LEFT);
97
if (substr($this->y,0,1) == "-")
98
$yStr = "-" . str_pad(substr($this->y, 1), 2, '0', STR_PAD_LEFT);
100
$filepath .= $this->imageId . "_" . $this->zoomLevel . "_" . $xStr . "_" . $yStr . ".$format";