diff --git a/webroot/img.php b/webroot/img.php index dc2faed..9e48c66 100644 --- a/webroot/img.php +++ b/webroot/img.php @@ -8,7 +8,7 @@ * */ -$version = "v0.7.9* (2015-12-07)"; +$version = "v0.7.10 (2016-04-01)"; // For CRemoteImage define("CIMAGE_USER_AGENT", "CImage/$version"); diff --git a/webroot/imgd.php b/webroot/imgd.php index a95868c..6977c2a 100755 --- a/webroot/imgd.php +++ b/webroot/imgd.php @@ -3817,7 +3817,7 @@ public function removeSubdir($subdir) * */ -$version = "v0.7.9* (2015-12-07)"; +$version = "v0.7.10 (2016-04-01)"; // For CRemoteImage define("CIMAGE_USER_AGENT", "CImage/$version"); diff --git a/webroot/imgp.php b/webroot/imgp.php index c48bdb0..e70e2d6 100755 --- a/webroot/imgp.php +++ b/webroot/imgp.php @@ -3817,7 +3817,7 @@ public function removeSubdir($subdir) * */ -$version = "v0.7.9* (2015-12-07)"; +$version = "v0.7.10 (2016-04-01)"; // For CRemoteImage define("CIMAGE_USER_AGENT", "CImage/$version"); diff --git a/webroot/imgs.php b/webroot/imgs.php index adb72d6..a124050 100644 --- a/webroot/imgs.php +++ b/webroot/imgs.php @@ -9,7 +9,7 @@
{$log}EOD; -} } private function raiseError($message) { throw new Exception($message); } } class CCache { private $path; public function setDir($path) { if (!is_dir($path)) { throw new Exception("Cachedir is not a directory."); } $this->path = $path; return $this; } public function getPathToSubdir($subdir, $create = true) { $path = realpath($this->path . "/" . $subdir); if (is_dir($path)) { return $path; } if ($create && is_writable($this->path)) { $path = $this->path . "/" . $subdir; if (mkdir($path)) { return realpath($path); } } return false; } public function getStatusOfSubdir($subdir) { $path = realpath($this->path . "/" . $subdir); $exists = is_dir($path); $res = $exists ? "exists" : "does not exist"; if ($exists) { $res .= is_writable($path) ? ", writable" : ", not writable"; } return $res; } public function removeSubdir($subdir) { $path = realpath($this->path . "/" . $subdir); if (is_dir($path)) { return rmdir($path); } return null; } } $version = "v0.7.9* (2015-12-07)"; define("CIMAGE_USER_AGENT", "CImage/$version"); function errorPage($msg, $type = 500) { global $mode; switch ($type) { case 403: $header = "403 Forbidden"; break; case 404: $header = "404 Not Found"; break; default: $header = "500 Internal Server Error"; } if ($mode == "strict") { $header = "404 Not Found"; } header("HTTP/1.0 $header"); if ($mode == "development") { die("[img.php] $msg"); } error_log("[img.php] $msg"); die("HTTP/1.0 $header"); } set_exception_handler(function ($exception) { errorPage( "
img.php: Uncaught exception:
" . $exception->getMessage() . "
" . $exception->getTraceAsString() . "", 500 ); }); function get($key, $default = null) { if (is_array($key)) { foreach ($key as $val) { if (isset($_GET[$val])) { return $_GET[$val]; } } } elseif (isset($_GET[$key])) { return $_GET[$key]; } return $default; } function getDefined($key, $defined, $undefined) { return get($key) === null ? $undefined : $defined; } function getConfig($key, $default) { global $config; return isset($config[$key]) ? $config[$key] : $default; } function verbose($msg = null) { global $verbose, $verboseFile; static $log = array(); if (!($verbose || $verboseFile)) { return; } if (is_null($msg)) { return $log; } $log[] = $msg; } $configFile = __DIR__.'/'.basename(__FILE__, '.php').'_config.php'; if (is_file($configFile)) { $config = require $configFile; } elseif (!isset($config)) { $config = array(); } $verbose = getDefined(array('verbose', 'v'), true, false); $verboseFile = getDefined('vf', true, false); verbose("img.php version = $version"); $status = getDefined('status', true, false); $mode = getConfig('mode', 'production'); set_time_limit(20); ini_set('gd.jpeg_ignore_warning', 1); if (!extension_loaded('gd')) { errorPage("Extension gd is not loaded.", 500); } if ($mode == 'strict') { error_reporting(0); ini_set('display_errors', 0); ini_set('log_errors', 1); $verbose = false; $status = false; $verboseFile = false; } elseif ($mode == 'production') { error_reporting(-1); ini_set('display_errors', 0); ini_set('log_errors', 1); $verbose = false; $status = false; $verboseFile = false; } elseif ($mode == 'development') { error_reporting(-1); ini_set('display_errors', 1); ini_set('log_errors', 0); $verboseFile = false; } elseif ($mode == 'test') { error_reporting(-1); ini_set('display_errors', 1); ini_set('log_errors', 0); } else { errorPage("Unknown mode: $mode", 500); } verbose("mode = $mode"); verbose("error log = " . ini_get('error_log')); $defaultTimezone = getConfig('default_timezone', null); if ($defaultTimezone) { date_default_timezone_set($defaultTimezone); } elseif (!ini_get('default_timezone')) { date_default_timezone_set('UTC'); } $pwdConfig = getConfig('password', false); $pwdAlways = getConfig('password_always', false); $pwdType = getConfig('password_type', 'text'); $pwd = get(array('password', 'pwd'), null); $passwordMatch = null; if ($pwd) { switch ($pwdType) { case 'md5': $passwordMatch = ($pwdConfig === md5($pwd)); break; case 'hash': $passwordMatch = password_verify($pwd, $pwdConfig); break; case 'text': $passwordMatch = ($pwdConfig === $pwd); break; default: $passwordMatch = false; } } if ($pwdAlways && $passwordMatch !== true) { errorPage("Password required and does not match or exists.", 403); } verbose("password match = $passwordMatch"); $allowHotlinking = getConfig('allow_hotlinking', true); $hotlinkingWhitelist = getConfig('hotlinking_whitelist', array()); $serverName = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null; $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null; $refererHost = parse_url($referer, PHP_URL_HOST); if (!$allowHotlinking) { if ($passwordMatch) { ; verbose("Hotlinking since passwordmatch"); } elseif ($passwordMatch === false) { errorPage("Hotlinking/leeching not allowed when password missmatch.", 403); } elseif (!$referer) { errorPage("Hotlinking/leeching not allowed and referer is missing.", 403); } elseif (strcmp($serverName, $refererHost) == 0) { ; verbose("Hotlinking disallowed but serverName matches refererHost."); } elseif (!empty($hotlinkingWhitelist)) { $whitelist = new CWhitelist(); $allowedByWhitelist = $whitelist->check($refererHost, $hotlinkingWhitelist); if ($allowedByWhitelist) { verbose("Hotlinking/leeching allowed by whitelist."); } else { errorPage("Hotlinking/leeching not allowed by whitelist. Referer: $referer.", 403); } } else { errorPage("Hotlinking/leeching not allowed.", 403); } } verbose("allow_hotlinking = $allowHotlinking"); verbose("referer = $referer"); verbose("referer host = $refererHost"); $autoloader = getConfig('autoloader', false); $cimageClass = getConfig('cimage_class', false); if ($autoloader) { require $autoloader; } elseif ($cimageClass) { require $cimageClass; } $img = new CImage(); $img->setVerbose($verbose || $verboseFile); $cachePath = getConfig('cache_path', __DIR__ . '/../cache/'); $cache = new CCache(); $cache->setDir($cachePath); $allowRemote = getConfig('remote_allow', false); if ($allowRemote && $passwordMatch !== false) { $cacheRemote = $cache->getPathToSubdir("remote"); $pattern = getConfig('remote_pattern', null); $img->setRemoteDownload($allowRemote, $cacheRemote, $pattern); $whitelist = getConfig('remote_whitelist', null); $img->setRemoteHostWhitelist($whitelist); } $shortcut = get(array('shortcut', 'sc'), null); $shortcutConfig = getConfig('shortcut', array( 'sepia' => "&f=grayscale&f0=brightness,-10&f1=contrast,-20&f2=colorize,120,60,0,0&sharpen", )); verbose("shortcut = $shortcut"); if (isset($shortcut) && isset($shortcutConfig[$shortcut])) { parse_str($shortcutConfig[$shortcut], $get); verbose("shortcut-constant = {$shortcutConfig[$shortcut]}"); $_GET = array_merge($_GET, $get); } $srcImage = urldecode(get('src')) or errorPage('Must set src-attribute.', 404); $srcAltImage = urldecode(get('src-alt', null)); $srcAltConfig = getConfig('src_alt', null); if (empty($srcAltImage)) { $srcAltImage = $srcAltConfig; } $imagePath = getConfig('image_path', __DIR__ . '/img/'); $imagePathConstraint = getConfig('image_path_constraint', true); $validFilename = getConfig('valid_filename', '#^[a-z0-9A-Z-/_ \.:]+$#'); $remoteSource = false; $dummyEnabled = getConfig('dummy_enabled', true); $dummyFilename = getConfig('dummy_filename', 'dummy'); $dummyImage = false; preg_match($validFilename, $srcImage) or errorPage('Source filename contains invalid characters.', 404); if ($dummyEnabled && $srcImage === $dummyFilename) { $dummyImage = true; } elseif ($allowRemote && $img->isRemoteSource($srcImage)) { $remoteSource = true; } else { $pathToImage = realpath($imagePath . $srcImage); if (!is_file($pathToImage) && !empty($srcAltImage)) { $srcImage = $srcAltImage; $pathToImage = realpath($imagePath . $srcImage); preg_match($validFilename, $srcImage) or errorPage('Source (alt) filename contains invalid characters.', 404); if ($dummyEnabled && $srcImage === $dummyFilename) { $dummyImage = true; } } if (!$dummyImage) { is_file($pathToImage) or errorPage( 'Source image is not a valid file, check the filename and that a +} } private function raiseError($message) { throw new Exception($message); } } class CCache { private $path; public function setDir($path) { if (!is_dir($path)) { throw new Exception("Cachedir is not a directory."); } $this->path = $path; return $this; } public function getPathToSubdir($subdir, $create = true) { $path = realpath($this->path . "/" . $subdir); if (is_dir($path)) { return $path; } if ($create && is_writable($this->path)) { $path = $this->path . "/" . $subdir; if (mkdir($path)) { return realpath($path); } } return false; } public function getStatusOfSubdir($subdir) { $path = realpath($this->path . "/" . $subdir); $exists = is_dir($path); $res = $exists ? "exists" : "does not exist"; if ($exists) { $res .= is_writable($path) ? ", writable" : ", not writable"; } return $res; } public function removeSubdir($subdir) { $path = realpath($this->path . "/" . $subdir); if (is_dir($path)) { return rmdir($path); } return null; } } $version = "v0.7.10 (2016-04-01)"; define("CIMAGE_USER_AGENT", "CImage/$version"); function errorPage($msg, $type = 500) { global $mode; switch ($type) { case 403: $header = "403 Forbidden"; break; case 404: $header = "404 Not Found"; break; default: $header = "500 Internal Server Error"; } if ($mode == "strict") { $header = "404 Not Found"; } header("HTTP/1.0 $header"); if ($mode == "development") { die("[img.php] $msg"); } error_log("[img.php] $msg"); die("HTTP/1.0 $header"); } set_exception_handler(function ($exception) { errorPage( "
img.php: Uncaught exception:
" . $exception->getMessage() . "
" . $exception->getTraceAsString() . "", 500 ); }); function get($key, $default = null) { if (is_array($key)) { foreach ($key as $val) { if (isset($_GET[$val])) { return $_GET[$val]; } } } elseif (isset($_GET[$key])) { return $_GET[$key]; } return $default; } function getDefined($key, $defined, $undefined) { return get($key) === null ? $undefined : $defined; } function getConfig($key, $default) { global $config; return isset($config[$key]) ? $config[$key] : $default; } function verbose($msg = null) { global $verbose, $verboseFile; static $log = array(); if (!($verbose || $verboseFile)) { return; } if (is_null($msg)) { return $log; } $log[] = $msg; } $configFile = __DIR__.'/'.basename(__FILE__, '.php').'_config.php'; if (is_file($configFile)) { $config = require $configFile; } elseif (!isset($config)) { $config = array(); } $verbose = getDefined(array('verbose', 'v'), true, false); $verboseFile = getDefined('vf', true, false); verbose("img.php version = $version"); $status = getDefined('status', true, false); $mode = getConfig('mode', 'production'); set_time_limit(20); ini_set('gd.jpeg_ignore_warning', 1); if (!extension_loaded('gd')) { errorPage("Extension gd is not loaded.", 500); } if ($mode == 'strict') { error_reporting(0); ini_set('display_errors', 0); ini_set('log_errors', 1); $verbose = false; $status = false; $verboseFile = false; } elseif ($mode == 'production') { error_reporting(-1); ini_set('display_errors', 0); ini_set('log_errors', 1); $verbose = false; $status = false; $verboseFile = false; } elseif ($mode == 'development') { error_reporting(-1); ini_set('display_errors', 1); ini_set('log_errors', 0); $verboseFile = false; } elseif ($mode == 'test') { error_reporting(-1); ini_set('display_errors', 1); ini_set('log_errors', 0); } else { errorPage("Unknown mode: $mode", 500); } verbose("mode = $mode"); verbose("error log = " . ini_get('error_log')); $defaultTimezone = getConfig('default_timezone', null); if ($defaultTimezone) { date_default_timezone_set($defaultTimezone); } elseif (!ini_get('default_timezone')) { date_default_timezone_set('UTC'); } $pwdConfig = getConfig('password', false); $pwdAlways = getConfig('password_always', false); $pwdType = getConfig('password_type', 'text'); $pwd = get(array('password', 'pwd'), null); $passwordMatch = null; if ($pwd) { switch ($pwdType) { case 'md5': $passwordMatch = ($pwdConfig === md5($pwd)); break; case 'hash': $passwordMatch = password_verify($pwd, $pwdConfig); break; case 'text': $passwordMatch = ($pwdConfig === $pwd); break; default: $passwordMatch = false; } } if ($pwdAlways && $passwordMatch !== true) { errorPage("Password required and does not match or exists.", 403); } verbose("password match = $passwordMatch"); $allowHotlinking = getConfig('allow_hotlinking', true); $hotlinkingWhitelist = getConfig('hotlinking_whitelist', array()); $serverName = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null; $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null; $refererHost = parse_url($referer, PHP_URL_HOST); if (!$allowHotlinking) { if ($passwordMatch) { ; verbose("Hotlinking since passwordmatch"); } elseif ($passwordMatch === false) { errorPage("Hotlinking/leeching not allowed when password missmatch.", 403); } elseif (!$referer) { errorPage("Hotlinking/leeching not allowed and referer is missing.", 403); } elseif (strcmp($serverName, $refererHost) == 0) { ; verbose("Hotlinking disallowed but serverName matches refererHost."); } elseif (!empty($hotlinkingWhitelist)) { $whitelist = new CWhitelist(); $allowedByWhitelist = $whitelist->check($refererHost, $hotlinkingWhitelist); if ($allowedByWhitelist) { verbose("Hotlinking/leeching allowed by whitelist."); } else { errorPage("Hotlinking/leeching not allowed by whitelist. Referer: $referer.", 403); } } else { errorPage("Hotlinking/leeching not allowed.", 403); } } verbose("allow_hotlinking = $allowHotlinking"); verbose("referer = $referer"); verbose("referer host = $refererHost"); $autoloader = getConfig('autoloader', false); $cimageClass = getConfig('cimage_class', false); if ($autoloader) { require $autoloader; } elseif ($cimageClass) { require $cimageClass; } $img = new CImage(); $img->setVerbose($verbose || $verboseFile); $cachePath = getConfig('cache_path', __DIR__ . '/../cache/'); $cache = new CCache(); $cache->setDir($cachePath); $allowRemote = getConfig('remote_allow', false); if ($allowRemote && $passwordMatch !== false) { $cacheRemote = $cache->getPathToSubdir("remote"); $pattern = getConfig('remote_pattern', null); $img->setRemoteDownload($allowRemote, $cacheRemote, $pattern); $whitelist = getConfig('remote_whitelist', null); $img->setRemoteHostWhitelist($whitelist); } $shortcut = get(array('shortcut', 'sc'), null); $shortcutConfig = getConfig('shortcut', array( 'sepia' => "&f=grayscale&f0=brightness,-10&f1=contrast,-20&f2=colorize,120,60,0,0&sharpen", )); verbose("shortcut = $shortcut"); if (isset($shortcut) && isset($shortcutConfig[$shortcut])) { parse_str($shortcutConfig[$shortcut], $get); verbose("shortcut-constant = {$shortcutConfig[$shortcut]}"); $_GET = array_merge($_GET, $get); } $srcImage = urldecode(get('src')) or errorPage('Must set src-attribute.', 404); $srcAltImage = urldecode(get('src-alt', null)); $srcAltConfig = getConfig('src_alt', null); if (empty($srcAltImage)) { $srcAltImage = $srcAltConfig; } $imagePath = getConfig('image_path', __DIR__ . '/img/'); $imagePathConstraint = getConfig('image_path_constraint', true); $validFilename = getConfig('valid_filename', '#^[a-z0-9A-Z-/_ \.:]+$#'); $remoteSource = false; $dummyEnabled = getConfig('dummy_enabled', true); $dummyFilename = getConfig('dummy_filename', 'dummy'); $dummyImage = false; preg_match($validFilename, $srcImage) or errorPage('Source filename contains invalid characters.', 404); if ($dummyEnabled && $srcImage === $dummyFilename) { $dummyImage = true; } elseif ($allowRemote && $img->isRemoteSource($srcImage)) { $remoteSource = true; } else { $pathToImage = realpath($imagePath . $srcImage); if (!is_file($pathToImage) && !empty($srcAltImage)) { $srcImage = $srcAltImage; $pathToImage = realpath($imagePath . $srcImage); preg_match($validFilename, $srcImage) or errorPage('Source (alt) filename contains invalid characters.', 404); if ($dummyEnabled && $srcImage === $dummyFilename) { $dummyImage = true; } } if (!$dummyImage) { is_file($pathToImage) or errorPage( 'Source image is not a valid file, check the filename and that a matching file exists on the filesystem.', 404 ); } } if ($imagePathConstraint && !$dummyImage && !$remoteSource) { $imageDir = realpath($imagePath); substr_compare($imageDir, $pathToImage, 0, strlen($imageDir)) == 0 or errorPage( 'Security constraint: Source image is not below the directory "image_path" as specified in the config file img_config.php.', 404 ); } verbose("src = $srcImage"); $sizeConstant = getConfig('size_constant', function () { $sizes = array( 'w1' => 613, 'w2' => 630, ); $gridColumnWidth = 30; $gridGutterWidth = 10; $gridColumns = 24; for ($i = 1; $i <= $gridColumns; $i++) { $sizes['c' . $i] = ($gridColumnWidth + $gridGutterWidth) * $i - $gridGutterWidth; } return $sizes; }); $sizes = call_user_func($sizeConstant); $newWidth = get(array('width', 'w')); $maxWidth = getConfig('max_width', 2000); if (isset($sizes[$newWidth])) { $newWidth = $sizes[$newWidth]; } if ($newWidth[strlen($newWidth)-1] == '%') { is_numeric(substr($newWidth, 0, -1)) or errorPage('Width % not numeric.', 404); } else { is_null($newWidth) or ($newWidth > 10 && $newWidth <= $maxWidth) or errorPage('Width out of range.', 404); } verbose("new width = $newWidth"); $newHeight = get(array('height', 'h')); $maxHeight = getConfig('max_height', 2000); if (isset($sizes[$newHeight])) { $newHeight = $sizes[$newHeight]; } if ($newHeight[strlen($newHeight)-1] == '%') { is_numeric(substr($newHeight, 0, -1)) or errorPage('Height % out of range.', 404); } else { is_null($newHeight) or ($newHeight > 10 && $newHeight <= $maxHeight) or errorPage('Height out of range.', 404); } verbose("new height = $newHeight"); $aspectRatio = get(array('aspect-ratio', 'ar')); $aspectRatioConstant = getConfig('aspect_ratio_constant', function () { return array( '3:1' => 3/1, '3:2' => 3/2, '4:3' => 4/3, '8:5' => 8/5, '16:10' => 16/10, '16:9' => 16/9, 'golden' => 1.618, ); }); $aspectRatios = call_user_func($aspectRatioConstant); $negateAspectRatio = ($aspectRatio[0] == '!') ? true : false; $aspectRatio = $negateAspectRatio ? substr($aspectRatio, 1) : $aspectRatio; if (isset($aspectRatios[$aspectRatio])) { $aspectRatio = $aspectRatios[$aspectRatio]; } if ($negateAspectRatio) { $aspectRatio = 1 / $aspectRatio; } is_null($aspectRatio) or is_numeric($aspectRatio) or errorPage('Aspect ratio out of range', 404); verbose("aspect ratio = $aspectRatio"); $cropToFit = getDefined(array('crop-to-fit', 'cf'), true, false); verbose("crop to fit = $cropToFit"); $backgroundColor = getConfig('background_color', null); if ($backgroundColor) { $img->setDefaultBackgroundColor($backgroundColor); verbose("Using default background_color = $backgroundColor"); } $bgColor = get(array('bgColor', 'bg-color', 'bgc'), null); verbose("bgColor = $bgColor"); $resizeStrategy = getDefined(array('no-resample'), true, false); if ($resizeStrategy) { $img->setCopyResizeStrategy($img::RESIZE); verbose("Setting = Resize instead of resample"); } $fillToFit = get(array('fill-to-fit', 'ff'), null); verbose("fill-to-fit = $fillToFit"); if ($fillToFit !== null) { if (!empty($fillToFit)) { $bgColor = $fillToFit; verbose("fillToFit changed bgColor to = $bgColor"); } $fillToFit = true; verbose("fill-to-fit (fixed) = $fillToFit"); } $keepRatio = getDefined(array('no-ratio', 'nr', 'stretch'), false, true); verbose("keep ratio = $keepRatio"); $crop = get(array('crop', 'c')); verbose("crop = $crop"); $area = get(array('area', 'a')); verbose("area = $area"); $useOriginal = getDefined(array('skip-original', 'so'), false, true); $useOriginalDefault = getConfig('skip_original', false); if ($useOriginalDefault === true) { verbose("use original is default ON"); $useOriginal = true; } verbose("use original = $useOriginal"); $useCache = getDefined(array('no-cache', 'nc'), false, true); verbose("use cache = $useCache"); $quality = get(array('quality', 'q')); $qualityDefault = getConfig('jpg_quality', null); is_null($quality) or ($quality > 0 and $quality <= 100) or errorPage('Quality out of range', 404); if (is_null($quality) && !is_null($qualityDefault)) { $quality = $qualityDefault; } verbose("quality = $quality"); $compress = get(array('compress', 'co')); $compressDefault = getConfig('png_compression', null); is_null($compress) or ($compress > 0 and $compress <= 9) or errorPage('Compress out of range', 404); if (is_null($compress) && !is_null($compressDefault)) { $compress = $compressDefault; } verbose("compress = $compress"); $saveAs = get(array('save-as', 'sa')); verbose("save as = $saveAs"); $scale = get(array('scale', 's')); is_null($scale) or ($scale >= 0 and $scale <= 400) or errorPage('Scale out of range', 404); verbose("scale = $scale"); $palette = getDefined(array('palette', 'p'), true, false); verbose("palette = $palette"); $sharpen = getDefined('sharpen', true, null); verbose("sharpen = $sharpen"); $emboss = getDefined('emboss', true, null); verbose("emboss = $emboss"); $blur = getDefined('blur', true, null); verbose("blur = $blur"); $rotateBefore = get(array('rotateBefore', 'rotate-before', 'rb')); is_null($rotateBefore) or ($rotateBefore >= -360 and $rotateBefore <= 360) or errorPage('RotateBefore out of range', 404); verbose("rotateBefore = $rotateBefore"); $rotateAfter = get(array('rotateAfter', 'rotate-after', 'ra', 'rotate', 'r')); is_null($rotateAfter) or ($rotateAfter >= -360 and $rotateAfter <= 360) or errorPage('RotateBefore out of range', 404); verbose("rotateAfter = $rotateAfter"); $autoRotate = getDefined(array('autoRotate', 'auto-rotate', 'aro'), true, false); verbose("autoRotate = $autoRotate"); $filters = array(); $filter = get(array('filter', 'f')); if ($filter) { $filters[] = $filter; } for ($i = 0; $i < 10; $i++) { $filter = get(array("filter{$i}", "f{$i}")); if ($filter) { $filters[] = $filter; } } verbose("filters = " . print_r($filters, 1)); $outputFormat = getDefined('json', 'json', null); $outputFormat = getDefined('ascii', 'ascii', $outputFormat); verbose("outputformat = $outputFormat"); if ($outputFormat == 'ascii') { $defaultOptions = getConfig( 'ascii-options', array( "characterSet" => 'two', "scale" => 14, "luminanceStrategy" => 3, "customCharacterSet" => null, ) ); $options = get('ascii'); $options = explode(',', $options); if (isset($options[0]) && !empty($options[0])) { $defaultOptions['characterSet'] = $options[0]; } if (isset($options[1]) && !empty($options[1])) { $defaultOptions['scale'] = $options[1]; } if (isset($options[2]) && !empty($options[2])) { $defaultOptions['luminanceStrategy'] = $options[2]; } if (count($options) > 3) { unset($options[0]); unset($options[1]); unset($options[2]); $characterString = implode($options); $defaultOptions['customCharacterSet'] = $characterString; } $img->setAsciiOptions($defaultOptions); } $dpr = get(array('ppi', 'dpr', 'device-pixel-ratio'), 1); verbose("dpr = $dpr"); $convolve = get('convolve', null); $convolutionConstant = getConfig('convolution_constant', array()); if ($convolve && isset($convolutionConstant)) { $img->addConvolveExpressions($convolutionConstant); verbose("convolve constant = " . print_r($convolutionConstant, 1)); } verbose("convolve = " . print_r($convolve, 1)); $upscale = getDefined(array('no-upscale', 'nu'), false, true); verbose("upscale = $upscale"); $postProcessing = getConfig('postprocessing', array( 'png_filter' => false, 'png_filter_cmd' => '/usr/local/bin/optipng -q', 'png_deflate' => false, 'png_deflate_cmd' => '/usr/local/bin/pngout -q', 'jpeg_optimize' => false, 'jpeg_optimize_cmd' => '/usr/local/bin/jpegtran -copy none -optimize', )); $alias = get('alias', null); $aliasPath = getConfig('alias_path', null); $validAliasname = getConfig('valid_aliasname', '#^[a-z0-9A-Z-_]+$#'); $aliasTarget = null; if ($alias && $aliasPath && $passwordMatch) { $aliasTarget = $aliasPath . $alias; $useCache = false; is_writable($aliasPath) or errorPage("Directory for alias is not writable.", 403); preg_match($validAliasname, $alias) or errorPage('Filename for alias contains invalid characters. Do not add extension.', 404); } elseif ($alias) { errorPage('Alias is not enabled in the config file or password not matching.', 403); } verbose("alias = $alias"); $cacheControl = getConfig('cache_control', null); if ($cacheControl) { verbose("cacheControl = $cacheControl"); $img->addHTTPHeader("Cache-Control", $cacheControl); } if ($dummyImage === true) { $dummyDir = $cache->getPathToSubdir("dummy"); $img->setSaveFolder($dummyDir) ->setSource($dummyFilename, $dummyDir) ->setOptions( array( 'newWidth' => $newWidth, 'newHeight' => $newHeight, 'bgColor' => $bgColor, ) ) ->setJpegQuality($quality) ->setPngCompression($compress) ->createDummyImage() ->generateFilename(null, false) ->save(null, null, false); $srcImage = $img->getTarget(); $imagePath = null; verbose("src (updated) = $srcImage"); } $srgbDefault = getConfig('srgb_default', false); $srgbColorProfile = getConfig('srgb_colorprofile', __DIR__ . '/../icc/sRGB_IEC61966-2-1_black_scaled.icc'); $srgb = getDefined('srgb', true, null); if ($srgb || $srgbDefault) { $filename = $img->convert2sRGBColorSpace( $srcImage, $imagePath, $cache->getPathToSubdir("srgb"), $srgbColorProfile, $useCache ); if ($filename) { $srcImage = $img->getTarget(); $imagePath = null; verbose("srgb conversion and saved to cache = $srcImage"); } else { verbose("srgb not op"); } } if ($status) { $text = "img.php version = $version\n"; $text .= "PHP version = " . PHP_VERSION . "\n"; $text .= "Running on: " . $_SERVER['SERVER_SOFTWARE'] . "\n"; $text .= "Allow remote images = $allowRemote\n"; $res = $cache->getStatusOfSubdir(""); $text .= "Cache $res\n"; $res = $cache->getStatusOfSubdir("remote"); $text .= "Cache remote $res\n"; $res = $cache->getStatusOfSubdir("dummy"); $text .= "Cache dummy $res\n"; $res = $cache->getStatusOfSubdir("srgb"); $text .= "Cache srgb $res\n"; $text .= "Alias path writable = " . is_writable($aliasPath) . "\n"; $no = extension_loaded('exif') ? null : 'NOT'; $text .= "Extension exif is $no loaded.