57 $this->invalidAction =
false;
58 $this->notFound =
false;
59 $this->rendered =
false;
63 if (isset($this->options[
'baseUrl']) && isset($this->options[
'cachePath'])) {
64 $baseUrl = rtrim($this->options[
'baseUrl'],
'/');
65 $this->cachePath = $this->options[
'cachePath'];
66 $relativePath = $this->options[
'relPath'] ??
'';
67 }
else if (defined(
'DEPAGE_PATH') && defined(
'DEPAGE_CACHE_PATH')) {
69 $info = parse_url(DEPAGE_BASE);
70 $baseUrl = rtrim($info[
'path'],
'/');
72 $this->cachePath = \DEPAGE_CACHE_PATH .
"graphics/";
75 $scriptParts = explode(
"/", $_SERVER[
"SCRIPT_NAME"]);
76 $uriParts = explode(
"/", $_SERVER[
"REQUEST_URI"]);
78 if (strpos($_SERVER[
"SCRIPT_NAME"],
"/lib/") !==
false) {
79 for ($i = 0; $i < count($uriParts); $i++) {
81 if ($uriParts[$i] ==
"lib") {
86 for ($i = 0; $i < count($uriParts); $i++) {
88 if ($scriptParts[$i] != $uriParts[$i]) {
93 $baseUrl = implode(
"/", array_slice($uriParts, 0, $i));
94 if (isset($this->options[
'relPath'])) {
95 $relativePath = $this->options[
'relPath'];
97 $relativePath = str_repeat(
"../", count($scriptParts) - $i - 1);
99 $this->cachePath = $relativePath .
"lib/cache/graphics/";
101 $baseUrlStatic = $baseUrl;
102 if (isset($this->options[
'baseUrlStatic'])) {
103 $baseUrlStatic = rtrim($this->options[
'baseUrlStatic'],
'/');
108 if ($baseUrl ==
"" && $baseUrlStatic ==
"") {
109 $imgUrl = substr($url, 1);
110 }
else if (strpos($url, $baseUrlStatic) === 0) {
111 $imgUrl = substr($url, strlen($baseUrlStatic) + 1);
112 }
else if (strpos($url, $baseUrl) === 0) {
113 $imgUrl = substr($url, strlen($baseUrl) + 1);
118 $success = preg_match(
"/(.*\.(jpg|jpeg|gif|png|webp|eps|tif|tiff|pdf|svg))\.([^\\\]*)\.(jpg|jpeg|gif|png|webp)/i", $imgUrl, $matches);
121 $this->invalidAction =
true;
126 $this->
id = rawurldecode($matches[0]);
127 $this->srcImg = $relativePath . rawurldecode($matches[1]);
128 $this->outImg = $this->cachePath . rawurldecode($matches[0]);
136 $actions = explode(
".", $actionString);
139 $regex = implode(
"|", array_keys($this->aliases));
140 preg_match(
"/^($regex)/i", $action, $matches);
142 if (isset($matches[1]) && isset($this->aliases[$matches[1]])) {
143 $func = $this->aliases[$matches[1]];
144 $params = substr($action, strlen($matches[1]));
151 $params = preg_split(
"/[-x,]+/", $params, -1, PREG_SPLIT_NO_EMPTY);
153 if ($func ==
"addBackground") {
154 if (!in_array($params[0], array(
"transparent",
"checkerboard"))) {
155 $params[0] =
"#{$params[0]}";
158 foreach ($params as $i => &$p) {
160 if ($p == 0 && $i < 2) {
166 $this->actions[] = array($func, $params);
168 $this->invalidAction =
true;
177 $url = $_SERVER[
"REQUEST_URI"];
181 if ($this->invalidAction) {
185 $outDir = dirname($this->outImg);
186 if (!is_dir($outDir)) {
187 mkdir($outDir, 0755,
true);
189 if (file_exists($this->outImg) && filemtime($this->outImg) >= filemtime($this->srcImg)) {
198 foreach ($this->actions as $action) {
199 list($func, $params) = $action;
200 if (is_callable(array($graphics, $func))) {
201 call_user_func_array(array($graphics, $func), $params);
206 $graphics->render($this->srcImg, $this->outImg);
208 $this->rendered =
true;
209 }
catch (Exceptions\FileNotFound $e) {
210 $this->notFound =
true;
212 }
catch (Exceptions\Exception $e) {
213 $this->invalidAction =
true;