From 1f012ac19ecbff809db86b6adb6285901cb71f0f Mon Sep 17 00:00:00 2001 From: Mikael Roos Date: Thu, 22 Oct 2015 16:52:08 +0200 Subject: [PATCH 01/11] production should be default mode --- webroot/img_config.php | 1 - 1 file changed, 1 deletion(-) diff --git a/webroot/img_config.php b/webroot/img_config.php index e84db44..cc7ab2c 100644 --- a/webroot/img_config.php +++ b/webroot/img_config.php @@ -13,7 +13,6 @@ return array( * Default values: * mode: 'production' */ - 'mode' => 'development', // 'development', 'strict' //'mode' => 'production', // 'development', 'strict' From b93d1242db02369761d2cbaaa0c38828c9a31115 Mon Sep 17 00:00:00 2001 From: Sony AK Date: Wed, 18 Nov 2015 11:34:22 +0700 Subject: [PATCH 02/11] fix the proper download URL --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 742790f..ff5ce2c 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ There are some all-included bundles of `img.php` that can be downloaded and used Dowload the version of your choice like this. ```bash -wget https://github.com/mosbth/cimage/tree/v0.7.7/webroot/imgp.php +wget https://raw.githubusercontent.com/mosbth/cimage/v0.7.7/webroot/imgp.php ``` Open up the file in your editor and edit the array `$config`. Ensure that the paths to the image directory and the cache directory matches your environment, or create an own config-file for the script. From 8aea13ba338a8b73c6f50568f7d97cb165e3ca73 Mon Sep 17 00:00:00 2001 From: The Gitter Badger Date: Mon, 23 Nov 2015 12:57:52 +0000 Subject: [PATCH 03/11] Add Gitter badge --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index ff5ce2c..ce64a7a 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ Image conversion on the fly using PHP ===================================== +[![Join the chat at https://gitter.im/mosbth/cimage](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/mosbth/cimage?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) + About ------------------------------------- From 3c22db4392a052a0f4a21ba39d7eb3a83e2b532f Mon Sep 17 00:00:00 2001 From: Anatolie Diordita Date: Tue, 24 Nov 2015 17:00:53 -0500 Subject: [PATCH 04/11] Added specific HTTP status messages to each error. --- webroot/img.php | 82 ++++++++++++++++++------------ webroot/imgd.php | 130 +++++++++++++++++++++++++++-------------------- webroot/imgp.php | 130 +++++++++++++++++++++++++++-------------------- 3 files changed, 198 insertions(+), 144 deletions(-) diff --git a/webroot/img.php b/webroot/img.php index d0b9be2..ed5114d 100644 --- a/webroot/img.php +++ b/webroot/img.php @@ -16,21 +16,39 @@ $version = "v0.7.7 (2015-10-21)"; * Display error message. * * @param string $msg to display. + * @param int $type of HTTP error to display. * * @return void */ -function errorPage($msg) +function errorPage($msg, $type = 500) { global $mode; - header("HTTP/1.0 500 Internal Server Error"); + switch ($type) { + case 400: + $header = "400 Bad Request"; + break; + case 401: + $header = "401 Unauthorized"; + break; + case 403: + $header = "403 Forbidden"; + break; + case 404: + $header = "404 Not Found"; + break; + default: + $header = "500 Internal Server Error"; + } + + header("HTTP/1.0 $header"); if ($mode == 'development') { die("[img.php] $msg"); } error_log("[img.php] $msg"); - die("HTTP/1.0 500 Internal Server Error"); + die("HTTP/1.0 $header"); } @@ -45,7 +63,7 @@ set_exception_handler(function ($exception) { . "

"
         . $exception->getTraceAsString()
         . "
" - ); + , 500); }); @@ -175,7 +193,7 @@ set_time_limit(20); ini_set('gd.jpeg_ignore_warning', 1); if (!extension_loaded('gd')) { - errorPage("Extension gd is nod loaded."); + errorPage("Extension gd is not loaded.", 500); } // Specific settings for each mode @@ -187,7 +205,7 @@ if ($mode == 'strict') { $verbose = false; $status = false; $verboseFile = false; - + } elseif ($mode == 'production') { error_reporting(-1); @@ -211,7 +229,7 @@ if ($mode == 'strict') { ini_set('log_errors', 0); } else { - errorPage("Unknown mode: $mode"); + errorPage("Unknown mode: $mode", 500); } verbose("mode = $mode"); @@ -260,7 +278,7 @@ if ($pwd) { } if ($pwdAlways && $passwordMatch !== true) { - errorPage("Password required and does not match or exists."); + errorPage("Password required and does not match or exists.", 401); } verbose("password match = $passwordMatch"); @@ -284,9 +302,9 @@ if (!$allowHotlinking) { ; // Always allow when password match verbose("Hotlinking since passwordmatch"); } elseif ($passwordMatch === false) { - errorPage("Hotlinking/leeching not allowed when password missmatch."); + errorPage("Hotlinking/leeching not allowed when password missmatch.", 401); } elseif (!$referer) { - errorPage("Hotlinking/leeching not allowed and referer is missing."); + errorPage("Hotlinking/leeching not allowed and referer is missing.", 403); } elseif (strcmp($serverName, $refererHost) == 0) { ; // Allow when serverName matches refererHost verbose("Hotlinking disallowed but serverName matches refererHost."); @@ -297,11 +315,11 @@ if (!$allowHotlinking) { if ($allowedByWhitelist) { verbose("Hotlinking/leeching allowed by whitelist."); } else { - errorPage("Hotlinking/leeching not allowed by whitelist. Referer: $referer."); + errorPage("Hotlinking/leeching not allowed by whitelist. Referer: $referer.", 403); } } else { - errorPage("Hotlinking/leeching not allowed."); + errorPage("Hotlinking/leeching not allowed.", 403); } } @@ -375,7 +393,7 @@ if (isset($shortcut) * src - the source image file. */ $srcImage = urldecode(get('src')) - or errorPage('Must set src-attribute.'); + or errorPage('Must set src-attribute.', 400); // Check for valid/invalid characters $imagePath = getConfig('image_path', __DIR__ . '/img/'); @@ -388,7 +406,7 @@ $dummyFilename = getConfig('dummy_filename', 'dummy'); $dummyImage = false; preg_match($validFilename, $srcImage) - or errorPage('Filename contains invalid characters.'); + or errorPage('Filename contains invalid characters.', 400); if ($dummyEnabled && $srcImage === $dummyFilename) { @@ -409,13 +427,13 @@ if ($dummyEnabled && $srcImage === $dummyFilename) { or errorPage( 'Source image is not a valid file, check the filename and that a matching file exists on the filesystem.' - ); + , 404); 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.' - ); + , 500); } verbose("src = $srcImage"); @@ -464,11 +482,11 @@ if (isset($sizes[$newWidth])) { // Support width as % of original width if ($newWidth[strlen($newWidth)-1] == '%') { is_numeric(substr($newWidth, 0, -1)) - or errorPage('Width % not numeric.'); + or errorPage('Width % not numeric.', 400); } else { is_null($newWidth) or ($newWidth > 10 && $newWidth <= $maxWidth) - or errorPage('Width out of range.'); + or errorPage('Width out of range.', 400); } verbose("new width = $newWidth"); @@ -489,11 +507,11 @@ if (isset($sizes[$newHeight])) { // height if ($newHeight[strlen($newHeight)-1] == '%') { is_numeric(substr($newHeight, 0, -1)) - or errorPage('Height % out of range.'); + or errorPage('Height % out of range.', 400); } else { is_null($newHeight) or ($newHeight > 10 && $newHeight <= $maxHeight) - or errorPage('Hight out of range.'); + or errorPage('Height out of range.', 400); } verbose("new height = $newHeight"); @@ -531,7 +549,7 @@ if ($negateAspectRatio) { is_null($aspectRatio) or is_numeric($aspectRatio) - or errorPage('Aspect ratio out of range'); + or errorPage('Aspect ratio out of range', 400); verbose("aspect ratio = $aspectRatio"); @@ -653,7 +671,7 @@ $qualityDefault = getConfig('jpg_quality', null); is_null($quality) or ($quality > 0 and $quality <= 100) - or errorPage('Quality out of range'); + or errorPage('Quality out of range', 400); if (is_null($quality) && !is_null($qualityDefault)) { $quality = $qualityDefault; @@ -671,7 +689,7 @@ $compressDefault = getConfig('png_compression', null); is_null($compress) or ($compress > 0 and $compress <= 9) - or errorPage('Compress out of range'); + or errorPage('Compress out of range', 400); if (is_null($compress) && !is_null($compressDefault)) { $compress = $compressDefault; @@ -697,7 +715,7 @@ $scale = get(array('scale', 's')); is_null($scale) or ($scale >= 0 and $scale <= 400) - or errorPage('Scale out of range'); + or errorPage('Scale out of range', 400); verbose("scale = $scale"); @@ -746,7 +764,7 @@ $rotateBefore = get(array('rotateBefore', 'rotate-before', 'rb')); is_null($rotateBefore) or ($rotateBefore >= -360 and $rotateBefore <= 360) - or errorPage('RotateBefore out of range'); + or errorPage('RotateBefore out of range', 400); verbose("rotateBefore = $rotateBefore"); @@ -759,7 +777,7 @@ $rotateAfter = get(array('rotateAfter', 'rotate-after', 'ra', 'rotate', 'r')); is_null($rotateAfter) or ($rotateAfter >= -360 and $rotateAfter <= 360) - or errorPage('RotateBefore out of range'); + or errorPage('RotateBefore out of range', 400); verbose("rotateAfter = $rotateAfter"); @@ -908,13 +926,13 @@ if ($alias && $aliasPath && $passwordMatch) { $useCache = false; is_writable($aliasPath) - or errorPage("Directory for alias is not writable."); + or errorPage("Directory for alias is not writable.", 500); preg_match($validAliasname, $alias) - or errorPage('Filename for alias contains invalid characters. Do not add extension.'); + or errorPage('Filename for alias contains invalid characters. Do not add extension.', 500); } elseif ($alias) { - errorPage('Alias is not enabled in the config file or password not matching.'); + errorPage('Alias is not enabled in the config file or password not matching.', 500); } verbose("alias = $alias"); @@ -966,7 +984,7 @@ if ($dummyImage === true) { $srcImage = $img->getTarget(); $imagePath = null; - + verbose("src (updated) = $srcImage"); } @@ -1025,7 +1043,7 @@ $hookBeforeCImage = getConfig('hook_before_CImage', null); if (is_callable($hookBeforeCImage)) { verbose("hookBeforeCImage activated"); - + $allConfig = $hookBeforeCImage($img, array( // Options for calculate dimensions 'newWidth' => $newWidth, @@ -1058,7 +1076,7 @@ if (is_callable($hookBeforeCImage)) { // Output format 'outputFormat' => $outputFormat, 'dpr' => $dpr, - + // Other 'postProcessing' => $postProcessing, )); diff --git a/webroot/imgd.php b/webroot/imgd.php index 9537886..8a55b3e 100644 --- a/webroot/imgd.php +++ b/webroot/imgd.php @@ -95,7 +95,7 @@ class CHttpGet public function setUrl($url) { $parts = parse_url($url); - + $path = ""; if (isset($parts['path'])) { $pathParts = explode('/', $parts['path']); @@ -139,7 +139,7 @@ class CHttpGet public function parseHeader() { //$header = explode("\r\n", rtrim($this->response['headerRaw'], "\r\n")); - + $rawHeaders = rtrim($this->response['headerRaw'], "\r\n"); # Handle multiple responses e.g. with redirections (proxies too) $headerGroups = explode("\r\n\r\n", $rawHeaders); @@ -624,7 +624,7 @@ class CRemoteImage $date = strtotime($this->cache['Date']); $maxAge = $this->cache['Max-Age']; $now = time(); - + if ($imageExists && $date + $maxAge > $now) { return $this->fileName; } @@ -687,11 +687,11 @@ class CWhitelist if ($whitelist !== null) { $this->set($whitelist); } - + if (empty($item) or empty($this->whitelist)) { return false; } - + foreach ($this->whitelist as $regexp) { if (preg_match("#$regexp#", $item)) { return true; @@ -791,17 +791,17 @@ class CAsciiArt "customCharacterSet" => null, ); $default = array_merge($default, $options); - + if (!is_null($default['customCharacterSet'])) { $this->addCharacterSet('custom', $default['customCharacterSet']); $default['characterSet'] = 'custom'; } - + $this->scale = $default['scale']; $this->characters = $this->characterSet[$default['characterSet']]; $this->charCount = strlen($this->characters); $this->luminanceStrategy = $default['luminanceStrategy']; - + return $this; } @@ -822,7 +822,7 @@ class CAsciiArt $ascii = null; $incY = $this->scale; $incX = $this->scale / 2; - + for ($y = 0; $y < $height - 1; $y += $incY) { for ($x = 0; $x < $width - 1; $x += $incX) { $toX = min($x + $this->scale / 2, $width - 1); @@ -853,7 +853,7 @@ class CAsciiArt { $numPixels = ($x2 - $x1 + 1) * ($y2 - $y1 + 1); $luminance = 0; - + for ($x = $x1; $x <= $x2; $x++) { for ($y = $y1; $y <= $y2; $y++) { $rgb = imagecolorat($img, $x, $y); @@ -863,7 +863,7 @@ class CAsciiArt $luminance += $this->getLuminance($red, $green, $blue); } } - + return $luminance / $numPixels; } @@ -1545,7 +1545,7 @@ class CImage private function normalizeFileExtension($extension = null) { $extension = strtolower($extension ? $extension : $this->extension); - + if ($extension == 'jpeg') { $extension = 'jpg'; } @@ -1567,7 +1567,7 @@ class CImage if (!$this->isRemoteSourceOnWhitelist($src)) { throw new Exception("Hostname is not on whitelist for remote sources."); } - + $remote = new CRemoteImage(); $cache = $this->saveFolder . "/remote/"; @@ -2241,7 +2241,7 @@ class CImage if ($this->copyStrategy === self::RESIZE) { $copyStrat = "_rs"; } - + $width = $this->newWidth; $height = $this->newHeight; @@ -2292,7 +2292,7 @@ class CImage $subdir = ($subdir == '.') ? '_.' : $subdir; $subdir .= '_'; } - + $file = $subdir . $filename . '_' . $width . '_' . $height . $offset . $crop . $cropToFit . $fillToFit . $crop_x . $crop_y . $upscale @@ -2363,7 +2363,7 @@ class CImage if ($this->image === false) { throw new Exception("Could not load image."); } - + /* Removed v0.7.7 if (image_type_to_mime_type($this->fileType) == 'image/png') { $type = $this->getPngType(); @@ -2403,14 +2403,14 @@ class CImage public function getPngType($filename = null) { $filename = $filename ? $filename : $this->pathToImage; - + $pngType = ord(file_get_contents($filename, false, null, 25, 1)); if ($this->verbose) { $this->log("Checking png type of: " . $filename); $this->log($this->getPngTypeAsString($pngType)); } - + return $pngType; } @@ -2434,7 +2434,7 @@ class CImage $index = imagecolortransparent($this->image); $transparent = null; if ($index != -1) { - $transparent = " (transparent)"; + $transparent = " (transparent)"; } switch ($pngType) { @@ -3141,7 +3141,7 @@ class CImage $index = $this->image ? imagecolortransparent($this->image) : -1; - + if ($index != -1) { imagealphablending($img, true); @@ -3209,8 +3209,8 @@ class CImage return substr(image_type_to_extension($this->fileType), 1); } } - - + + /** * Save image. @@ -3433,7 +3433,7 @@ class CImage $this->log("Content-type: " . $mime); $this->log("Content-length: " . $size); $this->verboseOutput(); - + if (is_null($this->verboseFileName)) { exit; } @@ -3485,7 +3485,7 @@ class CImage $details['memoryPeek'] = round(memory_get_peak_usage()/1024/1024, 3) . " MB" ; $details['memoryCurrent'] = round(memory_get_usage()/1024/1024, 3) . " MB"; $details['memoryLimit'] = ini_get('memory_limit'); - + if (isset($_SERVER['REQUEST_TIME_FLOAT'])) { $details['loadTime'] = (string) round((microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']), 3) . "s"; } @@ -3642,21 +3642,39 @@ $version = "v0.7.7 (2015-10-21)"; * Display error message. * * @param string $msg to display. + * @param int $type of HTTP error to display. * * @return void */ -function errorPage($msg) +function errorPage($msg, $type = 500) { global $mode; - header("HTTP/1.0 500 Internal Server Error"); + switch ($type) { + case 400: + $header = "400 Bad Request"; + break; + case 401: + $header = "401 Unauthorized"; + break; + case 403: + $header = "403 Forbidden"; + break; + case 404: + $header = "404 Not Found"; + break; + default: + $header = "500 Internal Server Error"; + } + + header("HTTP/1.0 $header"); if ($mode == 'development') { die("[img.php] $msg"); } error_log("[img.php] $msg"); - die("HTTP/1.0 500 Internal Server Error"); + die("HTTP/1.0 $header"); } @@ -3671,7 +3689,7 @@ set_exception_handler(function ($exception) { . "

"
         . $exception->getTraceAsString()
         . "
" - ); + , 500); }); @@ -3801,7 +3819,7 @@ set_time_limit(20); ini_set('gd.jpeg_ignore_warning', 1); if (!extension_loaded('gd')) { - errorPage("Extension gd is nod loaded."); + errorPage("Extension gd is not loaded.", 500); } // Specific settings for each mode @@ -3813,7 +3831,7 @@ if ($mode == 'strict') { $verbose = false; $status = false; $verboseFile = false; - + } elseif ($mode == 'production') { error_reporting(-1); @@ -3837,7 +3855,7 @@ if ($mode == 'strict') { ini_set('log_errors', 0); } else { - errorPage("Unknown mode: $mode"); + errorPage("Unknown mode: $mode", 500); } verbose("mode = $mode"); @@ -3886,7 +3904,7 @@ if ($pwd) { } if ($pwdAlways && $passwordMatch !== true) { - errorPage("Password required and does not match or exists."); + errorPage("Password required and does not match or exists.", 401); } verbose("password match = $passwordMatch"); @@ -3910,9 +3928,9 @@ if (!$allowHotlinking) { ; // Always allow when password match verbose("Hotlinking since passwordmatch"); } elseif ($passwordMatch === false) { - errorPage("Hotlinking/leeching not allowed when password missmatch."); + errorPage("Hotlinking/leeching not allowed when password missmatch.", 401); } elseif (!$referer) { - errorPage("Hotlinking/leeching not allowed and referer is missing."); + errorPage("Hotlinking/leeching not allowed and referer is missing.", 403); } elseif (strcmp($serverName, $refererHost) == 0) { ; // Allow when serverName matches refererHost verbose("Hotlinking disallowed but serverName matches refererHost."); @@ -3923,11 +3941,11 @@ if (!$allowHotlinking) { if ($allowedByWhitelist) { verbose("Hotlinking/leeching allowed by whitelist."); } else { - errorPage("Hotlinking/leeching not allowed by whitelist. Referer: $referer."); + errorPage("Hotlinking/leeching not allowed by whitelist. Referer: $referer.", 403); } } else { - errorPage("Hotlinking/leeching not allowed."); + errorPage("Hotlinking/leeching not allowed.", 403); } } @@ -4001,7 +4019,7 @@ if (isset($shortcut) * src - the source image file. */ $srcImage = urldecode(get('src')) - or errorPage('Must set src-attribute.'); + or errorPage('Must set src-attribute.', 400); // Check for valid/invalid characters $imagePath = getConfig('image_path', __DIR__ . '/img/'); @@ -4014,7 +4032,7 @@ $dummyFilename = getConfig('dummy_filename', 'dummy'); $dummyImage = false; preg_match($validFilename, $srcImage) - or errorPage('Filename contains invalid characters.'); + or errorPage('Filename contains invalid characters.', 400); if ($dummyEnabled && $srcImage === $dummyFilename) { @@ -4035,13 +4053,13 @@ if ($dummyEnabled && $srcImage === $dummyFilename) { or errorPage( 'Source image is not a valid file, check the filename and that a matching file exists on the filesystem.' - ); + , 404); 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.' - ); + , 500); } verbose("src = $srcImage"); @@ -4090,11 +4108,11 @@ if (isset($sizes[$newWidth])) { // Support width as % of original width if ($newWidth[strlen($newWidth)-1] == '%') { is_numeric(substr($newWidth, 0, -1)) - or errorPage('Width % not numeric.'); + or errorPage('Width % not numeric.', 400); } else { is_null($newWidth) or ($newWidth > 10 && $newWidth <= $maxWidth) - or errorPage('Width out of range.'); + or errorPage('Width out of range.', 400); } verbose("new width = $newWidth"); @@ -4115,11 +4133,11 @@ if (isset($sizes[$newHeight])) { // height if ($newHeight[strlen($newHeight)-1] == '%') { is_numeric(substr($newHeight, 0, -1)) - or errorPage('Height % out of range.'); + or errorPage('Height % out of range.', 400); } else { is_null($newHeight) or ($newHeight > 10 && $newHeight <= $maxHeight) - or errorPage('Hight out of range.'); + or errorPage('Height out of range.', 400); } verbose("new height = $newHeight"); @@ -4157,7 +4175,7 @@ if ($negateAspectRatio) { is_null($aspectRatio) or is_numeric($aspectRatio) - or errorPage('Aspect ratio out of range'); + or errorPage('Aspect ratio out of range', 400); verbose("aspect ratio = $aspectRatio"); @@ -4279,7 +4297,7 @@ $qualityDefault = getConfig('jpg_quality', null); is_null($quality) or ($quality > 0 and $quality <= 100) - or errorPage('Quality out of range'); + or errorPage('Quality out of range', 400); if (is_null($quality) && !is_null($qualityDefault)) { $quality = $qualityDefault; @@ -4297,7 +4315,7 @@ $compressDefault = getConfig('png_compression', null); is_null($compress) or ($compress > 0 and $compress <= 9) - or errorPage('Compress out of range'); + or errorPage('Compress out of range', 400); if (is_null($compress) && !is_null($compressDefault)) { $compress = $compressDefault; @@ -4323,7 +4341,7 @@ $scale = get(array('scale', 's')); is_null($scale) or ($scale >= 0 and $scale <= 400) - or errorPage('Scale out of range'); + or errorPage('Scale out of range', 400); verbose("scale = $scale"); @@ -4372,7 +4390,7 @@ $rotateBefore = get(array('rotateBefore', 'rotate-before', 'rb')); is_null($rotateBefore) or ($rotateBefore >= -360 and $rotateBefore <= 360) - or errorPage('RotateBefore out of range'); + or errorPage('RotateBefore out of range', 400); verbose("rotateBefore = $rotateBefore"); @@ -4385,7 +4403,7 @@ $rotateAfter = get(array('rotateAfter', 'rotate-after', 'ra', 'rotate', 'r')); is_null($rotateAfter) or ($rotateAfter >= -360 and $rotateAfter <= 360) - or errorPage('RotateBefore out of range'); + or errorPage('RotateBefore out of range', 400); verbose("rotateAfter = $rotateAfter"); @@ -4534,13 +4552,13 @@ if ($alias && $aliasPath && $passwordMatch) { $useCache = false; is_writable($aliasPath) - or errorPage("Directory for alias is not writable."); + or errorPage("Directory for alias is not writable.", 500); preg_match($validAliasname, $alias) - or errorPage('Filename for alias contains invalid characters. Do not add extension.'); + or errorPage('Filename for alias contains invalid characters. Do not add extension.', 500); } elseif ($alias) { - errorPage('Alias is not enabled in the config file or password not matching.'); + errorPage('Alias is not enabled in the config file or password not matching.', 500); } verbose("alias = $alias"); @@ -4592,7 +4610,7 @@ if ($dummyImage === true) { $srcImage = $img->getTarget(); $imagePath = null; - + verbose("src (updated) = $srcImage"); } @@ -4651,7 +4669,7 @@ $hookBeforeCImage = getConfig('hook_before_CImage', null); if (is_callable($hookBeforeCImage)) { verbose("hookBeforeCImage activated"); - + $allConfig = $hookBeforeCImage($img, array( // Options for calculate dimensions 'newWidth' => $newWidth, @@ -4684,7 +4702,7 @@ if (is_callable($hookBeforeCImage)) { // Output format 'outputFormat' => $outputFormat, 'dpr' => $dpr, - + // Other 'postProcessing' => $postProcessing, )); diff --git a/webroot/imgp.php b/webroot/imgp.php index 08975aa..03a45e9 100644 --- a/webroot/imgp.php +++ b/webroot/imgp.php @@ -95,7 +95,7 @@ class CHttpGet public function setUrl($url) { $parts = parse_url($url); - + $path = ""; if (isset($parts['path'])) { $pathParts = explode('/', $parts['path']); @@ -139,7 +139,7 @@ class CHttpGet public function parseHeader() { //$header = explode("\r\n", rtrim($this->response['headerRaw'], "\r\n")); - + $rawHeaders = rtrim($this->response['headerRaw'], "\r\n"); # Handle multiple responses e.g. with redirections (proxies too) $headerGroups = explode("\r\n\r\n", $rawHeaders); @@ -624,7 +624,7 @@ class CRemoteImage $date = strtotime($this->cache['Date']); $maxAge = $this->cache['Max-Age']; $now = time(); - + if ($imageExists && $date + $maxAge > $now) { return $this->fileName; } @@ -687,11 +687,11 @@ class CWhitelist if ($whitelist !== null) { $this->set($whitelist); } - + if (empty($item) or empty($this->whitelist)) { return false; } - + foreach ($this->whitelist as $regexp) { if (preg_match("#$regexp#", $item)) { return true; @@ -791,17 +791,17 @@ class CAsciiArt "customCharacterSet" => null, ); $default = array_merge($default, $options); - + if (!is_null($default['customCharacterSet'])) { $this->addCharacterSet('custom', $default['customCharacterSet']); $default['characterSet'] = 'custom'; } - + $this->scale = $default['scale']; $this->characters = $this->characterSet[$default['characterSet']]; $this->charCount = strlen($this->characters); $this->luminanceStrategy = $default['luminanceStrategy']; - + return $this; } @@ -822,7 +822,7 @@ class CAsciiArt $ascii = null; $incY = $this->scale; $incX = $this->scale / 2; - + for ($y = 0; $y < $height - 1; $y += $incY) { for ($x = 0; $x < $width - 1; $x += $incX) { $toX = min($x + $this->scale / 2, $width - 1); @@ -853,7 +853,7 @@ class CAsciiArt { $numPixels = ($x2 - $x1 + 1) * ($y2 - $y1 + 1); $luminance = 0; - + for ($x = $x1; $x <= $x2; $x++) { for ($y = $y1; $y <= $y2; $y++) { $rgb = imagecolorat($img, $x, $y); @@ -863,7 +863,7 @@ class CAsciiArt $luminance += $this->getLuminance($red, $green, $blue); } } - + return $luminance / $numPixels; } @@ -1545,7 +1545,7 @@ class CImage private function normalizeFileExtension($extension = null) { $extension = strtolower($extension ? $extension : $this->extension); - + if ($extension == 'jpeg') { $extension = 'jpg'; } @@ -1567,7 +1567,7 @@ class CImage if (!$this->isRemoteSourceOnWhitelist($src)) { throw new Exception("Hostname is not on whitelist for remote sources."); } - + $remote = new CRemoteImage(); $cache = $this->saveFolder . "/remote/"; @@ -2241,7 +2241,7 @@ class CImage if ($this->copyStrategy === self::RESIZE) { $copyStrat = "_rs"; } - + $width = $this->newWidth; $height = $this->newHeight; @@ -2292,7 +2292,7 @@ class CImage $subdir = ($subdir == '.') ? '_.' : $subdir; $subdir .= '_'; } - + $file = $subdir . $filename . '_' . $width . '_' . $height . $offset . $crop . $cropToFit . $fillToFit . $crop_x . $crop_y . $upscale @@ -2363,7 +2363,7 @@ class CImage if ($this->image === false) { throw new Exception("Could not load image."); } - + /* Removed v0.7.7 if (image_type_to_mime_type($this->fileType) == 'image/png') { $type = $this->getPngType(); @@ -2403,14 +2403,14 @@ class CImage public function getPngType($filename = null) { $filename = $filename ? $filename : $this->pathToImage; - + $pngType = ord(file_get_contents($filename, false, null, 25, 1)); if ($this->verbose) { $this->log("Checking png type of: " . $filename); $this->log($this->getPngTypeAsString($pngType)); } - + return $pngType; } @@ -2434,7 +2434,7 @@ class CImage $index = imagecolortransparent($this->image); $transparent = null; if ($index != -1) { - $transparent = " (transparent)"; + $transparent = " (transparent)"; } switch ($pngType) { @@ -3141,7 +3141,7 @@ class CImage $index = $this->image ? imagecolortransparent($this->image) : -1; - + if ($index != -1) { imagealphablending($img, true); @@ -3209,8 +3209,8 @@ class CImage return substr(image_type_to_extension($this->fileType), 1); } } - - + + /** * Save image. @@ -3433,7 +3433,7 @@ class CImage $this->log("Content-type: " . $mime); $this->log("Content-length: " . $size); $this->verboseOutput(); - + if (is_null($this->verboseFileName)) { exit; } @@ -3485,7 +3485,7 @@ class CImage $details['memoryPeek'] = round(memory_get_peak_usage()/1024/1024, 3) . " MB" ; $details['memoryCurrent'] = round(memory_get_usage()/1024/1024, 3) . " MB"; $details['memoryLimit'] = ini_get('memory_limit'); - + if (isset($_SERVER['REQUEST_TIME_FLOAT'])) { $details['loadTime'] = (string) round((microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']), 3) . "s"; } @@ -3642,21 +3642,39 @@ $version = "v0.7.7 (2015-10-21)"; * Display error message. * * @param string $msg to display. + * @param int $type of HTTP error to display. * * @return void */ -function errorPage($msg) +function errorPage($msg, $type = 500) { global $mode; - header("HTTP/1.0 500 Internal Server Error"); + switch ($type) { + case 400: + $header = "400 Bad Request"; + break; + case 401: + $header = "401 Unauthorized"; + break; + case 403: + $header = "403 Forbidden"; + break; + case 404: + $header = "404 Not Found"; + break; + default: + $header = "500 Internal Server Error"; + } + + header("HTTP/1.0 $header"); if ($mode == 'development') { die("[img.php] $msg"); } error_log("[img.php] $msg"); - die("HTTP/1.0 500 Internal Server Error"); + die("HTTP/1.0 $header"); } @@ -3671,7 +3689,7 @@ set_exception_handler(function ($exception) { . "

"
         . $exception->getTraceAsString()
         . "
" - ); + , 500); }); @@ -3801,7 +3819,7 @@ set_time_limit(20); ini_set('gd.jpeg_ignore_warning', 1); if (!extension_loaded('gd')) { - errorPage("Extension gd is nod loaded."); + errorPage("Extension gd is not loaded.", 500); } // Specific settings for each mode @@ -3813,7 +3831,7 @@ if ($mode == 'strict') { $verbose = false; $status = false; $verboseFile = false; - + } elseif ($mode == 'production') { error_reporting(-1); @@ -3837,7 +3855,7 @@ if ($mode == 'strict') { ini_set('log_errors', 0); } else { - errorPage("Unknown mode: $mode"); + errorPage("Unknown mode: $mode", 500); } verbose("mode = $mode"); @@ -3886,7 +3904,7 @@ if ($pwd) { } if ($pwdAlways && $passwordMatch !== true) { - errorPage("Password required and does not match or exists."); + errorPage("Password required and does not match or exists.", 401); } verbose("password match = $passwordMatch"); @@ -3910,9 +3928,9 @@ if (!$allowHotlinking) { ; // Always allow when password match verbose("Hotlinking since passwordmatch"); } elseif ($passwordMatch === false) { - errorPage("Hotlinking/leeching not allowed when password missmatch."); + errorPage("Hotlinking/leeching not allowed when password missmatch.", 401); } elseif (!$referer) { - errorPage("Hotlinking/leeching not allowed and referer is missing."); + errorPage("Hotlinking/leeching not allowed and referer is missing.", 403); } elseif (strcmp($serverName, $refererHost) == 0) { ; // Allow when serverName matches refererHost verbose("Hotlinking disallowed but serverName matches refererHost."); @@ -3923,11 +3941,11 @@ if (!$allowHotlinking) { if ($allowedByWhitelist) { verbose("Hotlinking/leeching allowed by whitelist."); } else { - errorPage("Hotlinking/leeching not allowed by whitelist. Referer: $referer."); + errorPage("Hotlinking/leeching not allowed by whitelist. Referer: $referer.", 403); } } else { - errorPage("Hotlinking/leeching not allowed."); + errorPage("Hotlinking/leeching not allowed.", 403); } } @@ -4001,7 +4019,7 @@ if (isset($shortcut) * src - the source image file. */ $srcImage = urldecode(get('src')) - or errorPage('Must set src-attribute.'); + or errorPage('Must set src-attribute.', 400); // Check for valid/invalid characters $imagePath = getConfig('image_path', __DIR__ . '/img/'); @@ -4014,7 +4032,7 @@ $dummyFilename = getConfig('dummy_filename', 'dummy'); $dummyImage = false; preg_match($validFilename, $srcImage) - or errorPage('Filename contains invalid characters.'); + or errorPage('Filename contains invalid characters.', 400); if ($dummyEnabled && $srcImage === $dummyFilename) { @@ -4035,13 +4053,13 @@ if ($dummyEnabled && $srcImage === $dummyFilename) { or errorPage( 'Source image is not a valid file, check the filename and that a matching file exists on the filesystem.' - ); + , 404); 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.' - ); + , 500); } verbose("src = $srcImage"); @@ -4090,11 +4108,11 @@ if (isset($sizes[$newWidth])) { // Support width as % of original width if ($newWidth[strlen($newWidth)-1] == '%') { is_numeric(substr($newWidth, 0, -1)) - or errorPage('Width % not numeric.'); + or errorPage('Width % not numeric.', 400); } else { is_null($newWidth) or ($newWidth > 10 && $newWidth <= $maxWidth) - or errorPage('Width out of range.'); + or errorPage('Width out of range.', 400); } verbose("new width = $newWidth"); @@ -4115,11 +4133,11 @@ if (isset($sizes[$newHeight])) { // height if ($newHeight[strlen($newHeight)-1] == '%') { is_numeric(substr($newHeight, 0, -1)) - or errorPage('Height % out of range.'); + or errorPage('Height % out of range.', 400); } else { is_null($newHeight) or ($newHeight > 10 && $newHeight <= $maxHeight) - or errorPage('Hight out of range.'); + or errorPage('Height out of range.', 400); } verbose("new height = $newHeight"); @@ -4157,7 +4175,7 @@ if ($negateAspectRatio) { is_null($aspectRatio) or is_numeric($aspectRatio) - or errorPage('Aspect ratio out of range'); + or errorPage('Aspect ratio out of range', 400); verbose("aspect ratio = $aspectRatio"); @@ -4279,7 +4297,7 @@ $qualityDefault = getConfig('jpg_quality', null); is_null($quality) or ($quality > 0 and $quality <= 100) - or errorPage('Quality out of range'); + or errorPage('Quality out of range', 400); if (is_null($quality) && !is_null($qualityDefault)) { $quality = $qualityDefault; @@ -4297,7 +4315,7 @@ $compressDefault = getConfig('png_compression', null); is_null($compress) or ($compress > 0 and $compress <= 9) - or errorPage('Compress out of range'); + or errorPage('Compress out of range', 400); if (is_null($compress) && !is_null($compressDefault)) { $compress = $compressDefault; @@ -4323,7 +4341,7 @@ $scale = get(array('scale', 's')); is_null($scale) or ($scale >= 0 and $scale <= 400) - or errorPage('Scale out of range'); + or errorPage('Scale out of range', 400); verbose("scale = $scale"); @@ -4372,7 +4390,7 @@ $rotateBefore = get(array('rotateBefore', 'rotate-before', 'rb')); is_null($rotateBefore) or ($rotateBefore >= -360 and $rotateBefore <= 360) - or errorPage('RotateBefore out of range'); + or errorPage('RotateBefore out of range', 400); verbose("rotateBefore = $rotateBefore"); @@ -4385,7 +4403,7 @@ $rotateAfter = get(array('rotateAfter', 'rotate-after', 'ra', 'rotate', 'r')); is_null($rotateAfter) or ($rotateAfter >= -360 and $rotateAfter <= 360) - or errorPage('RotateBefore out of range'); + or errorPage('RotateBefore out of range', 400); verbose("rotateAfter = $rotateAfter"); @@ -4534,13 +4552,13 @@ if ($alias && $aliasPath && $passwordMatch) { $useCache = false; is_writable($aliasPath) - or errorPage("Directory for alias is not writable."); + or errorPage("Directory for alias is not writable.", 500); preg_match($validAliasname, $alias) - or errorPage('Filename for alias contains invalid characters. Do not add extension.'); + or errorPage('Filename for alias contains invalid characters. Do not add extension.', 500); } elseif ($alias) { - errorPage('Alias is not enabled in the config file or password not matching.'); + errorPage('Alias is not enabled in the config file or password not matching.', 500); } verbose("alias = $alias"); @@ -4592,7 +4610,7 @@ if ($dummyImage === true) { $srcImage = $img->getTarget(); $imagePath = null; - + verbose("src (updated) = $srcImage"); } @@ -4651,7 +4669,7 @@ $hookBeforeCImage = getConfig('hook_before_CImage', null); if (is_callable($hookBeforeCImage)) { verbose("hookBeforeCImage activated"); - + $allConfig = $hookBeforeCImage($img, array( // Options for calculate dimensions 'newWidth' => $newWidth, @@ -4684,7 +4702,7 @@ if (is_callable($hookBeforeCImage)) { // Output format 'outputFormat' => $outputFormat, 'dpr' => $dpr, - + // Other 'postProcessing' => $postProcessing, )); From 39cee7647e82b92cf26188251f016e3daefb0ceb Mon Sep 17 00:00:00 2001 From: Mikael Roos Date: Wed, 25 Nov 2015 10:04:24 +0100 Subject: [PATCH 05/11] Added Gitter badge to README, #126. --- README.md | 5 ++--- REVISION.md | 7 +++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ce64a7a..8193cf2 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,9 @@ -[![Build Status](https://travis-ci.org/mosbth/cimage.svg?branch=master)](https://travis-ci.org/mosbth/cimage) -[![Build Status](https://scrutinizer-ci.com/g/mosbth/cimage/badges/build.png?b=master)](https://scrutinizer-ci.com/g/mosbth/cimage/build-status/master) - Image conversion on the fly using PHP ===================================== [![Join the chat at https://gitter.im/mosbth/cimage](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/mosbth/cimage?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +[![Build Status](https://travis-ci.org/mosbth/cimage.svg?branch=master)](https://travis-ci.org/mosbth/cimage) +[![Build Status](https://scrutinizer-ci.com/g/mosbth/cimage/badges/build.png?b=master)](https://scrutinizer-ci.com/g/mosbth/cimage/build-status/master) About ------------------------------------- diff --git a/REVISION.md b/REVISION.md index 3473578..300976a 100644 --- a/REVISION.md +++ b/REVISION.md @@ -5,6 +5,13 @@ Revision history [![Build Status](https://scrutinizer-ci.com/g/mosbth/cimage/badges/build.png?b=master)](https://scrutinizer-ci.com/g/mosbth/cimage/build-status/master) +v0.7.7* (2015-10-25) +------------------------------------- + +* Added Gitter badge to README, #126. +* Fix proper download url in README, #125. + + v0.7.7 (2015-10-21) ------------------------------------- From d7b34a64880bb737893bbdb936520bcf973dec4e Mon Sep 17 00:00:00 2001 From: Anatolie Diordita Date: Sun, 29 Nov 2015 15:23:39 -0500 Subject: [PATCH 06/11] Updated to reflect changes proposed in issue #127 --- webroot/img.php | 42 +++++++-------- webroot/imgd.php | 130 ++++++++++++++++++++--------------------------- webroot/imgp.php | 130 ++++++++++++++++++++--------------------------- webroot/imgs.php | 0 4 files changed, 130 insertions(+), 172 deletions(-) mode change 100644 => 100755 webroot/imgd.php mode change 100644 => 100755 webroot/imgp.php mode change 100644 => 100755 webroot/imgs.php diff --git a/webroot/img.php b/webroot/img.php index ed5114d..72e6bea 100644 --- a/webroot/img.php +++ b/webroot/img.php @@ -25,12 +25,6 @@ function errorPage($msg, $type = 500) global $mode; switch ($type) { - case 400: - $header = "400 Bad Request"; - break; - case 401: - $header = "401 Unauthorized"; - break; case 403: $header = "403 Forbidden"; break; @@ -278,7 +272,7 @@ if ($pwd) { } if ($pwdAlways && $passwordMatch !== true) { - errorPage("Password required and does not match or exists.", 401); + errorPage("Password required and does not match or exists.", 403); } verbose("password match = $passwordMatch"); @@ -302,7 +296,7 @@ if (!$allowHotlinking) { ; // Always allow when password match verbose("Hotlinking since passwordmatch"); } elseif ($passwordMatch === false) { - errorPage("Hotlinking/leeching not allowed when password missmatch.", 401); + 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) { @@ -393,7 +387,7 @@ if (isset($shortcut) * src - the source image file. */ $srcImage = urldecode(get('src')) - or errorPage('Must set src-attribute.', 400); + or errorPage('Must set src-attribute.', 404); // Check for valid/invalid characters $imagePath = getConfig('image_path', __DIR__ . '/img/'); @@ -406,7 +400,7 @@ $dummyFilename = getConfig('dummy_filename', 'dummy'); $dummyImage = false; preg_match($validFilename, $srcImage) - or errorPage('Filename contains invalid characters.', 400); + or errorPage('Filename contains invalid characters.', 404); if ($dummyEnabled && $srcImage === $dummyFilename) { @@ -433,7 +427,7 @@ if ($dummyEnabled && $srcImage === $dummyFilename) { or errorPage( 'Security constraint: Source image is not below the directory "image_path" as specified in the config file img_config.php.' - , 500); + , 404); } verbose("src = $srcImage"); @@ -482,11 +476,11 @@ if (isset($sizes[$newWidth])) { // Support width as % of original width if ($newWidth[strlen($newWidth)-1] == '%') { is_numeric(substr($newWidth, 0, -1)) - or errorPage('Width % not numeric.', 400); + or errorPage('Width % not numeric.', 404); } else { is_null($newWidth) or ($newWidth > 10 && $newWidth <= $maxWidth) - or errorPage('Width out of range.', 400); + or errorPage('Width out of range.', 404); } verbose("new width = $newWidth"); @@ -507,11 +501,11 @@ if (isset($sizes[$newHeight])) { // height if ($newHeight[strlen($newHeight)-1] == '%') { is_numeric(substr($newHeight, 0, -1)) - or errorPage('Height % out of range.', 400); + or errorPage('Height % out of range.', 404); } else { is_null($newHeight) or ($newHeight > 10 && $newHeight <= $maxHeight) - or errorPage('Height out of range.', 400); + or errorPage('Height out of range.', 404); } verbose("new height = $newHeight"); @@ -549,7 +543,7 @@ if ($negateAspectRatio) { is_null($aspectRatio) or is_numeric($aspectRatio) - or errorPage('Aspect ratio out of range', 400); + or errorPage('Aspect ratio out of range', 404); verbose("aspect ratio = $aspectRatio"); @@ -671,7 +665,7 @@ $qualityDefault = getConfig('jpg_quality', null); is_null($quality) or ($quality > 0 and $quality <= 100) - or errorPage('Quality out of range', 400); + or errorPage('Quality out of range', 404); if (is_null($quality) && !is_null($qualityDefault)) { $quality = $qualityDefault; @@ -689,7 +683,7 @@ $compressDefault = getConfig('png_compression', null); is_null($compress) or ($compress > 0 and $compress <= 9) - or errorPage('Compress out of range', 400); + or errorPage('Compress out of range', 404); if (is_null($compress) && !is_null($compressDefault)) { $compress = $compressDefault; @@ -715,7 +709,7 @@ $scale = get(array('scale', 's')); is_null($scale) or ($scale >= 0 and $scale <= 400) - or errorPage('Scale out of range', 400); + or errorPage('Scale out of range', 404); verbose("scale = $scale"); @@ -764,7 +758,7 @@ $rotateBefore = get(array('rotateBefore', 'rotate-before', 'rb')); is_null($rotateBefore) or ($rotateBefore >= -360 and $rotateBefore <= 360) - or errorPage('RotateBefore out of range', 400); + or errorPage('RotateBefore out of range', 404); verbose("rotateBefore = $rotateBefore"); @@ -777,7 +771,7 @@ $rotateAfter = get(array('rotateAfter', 'rotate-after', 'ra', 'rotate', 'r')); is_null($rotateAfter) or ($rotateAfter >= -360 and $rotateAfter <= 360) - or errorPage('RotateBefore out of range', 400); + or errorPage('RotateBefore out of range', 404); verbose("rotateAfter = $rotateAfter"); @@ -926,13 +920,13 @@ if ($alias && $aliasPath && $passwordMatch) { $useCache = false; is_writable($aliasPath) - or errorPage("Directory for alias is not writable.", 500); + 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.', 500); + 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.', 500); + errorPage('Alias is not enabled in the config file or password not matching.', 403); } verbose("alias = $alias"); diff --git a/webroot/imgd.php b/webroot/imgd.php old mode 100644 new mode 100755 index 8a55b3e..9537886 --- a/webroot/imgd.php +++ b/webroot/imgd.php @@ -95,7 +95,7 @@ class CHttpGet public function setUrl($url) { $parts = parse_url($url); - + $path = ""; if (isset($parts['path'])) { $pathParts = explode('/', $parts['path']); @@ -139,7 +139,7 @@ class CHttpGet public function parseHeader() { //$header = explode("\r\n", rtrim($this->response['headerRaw'], "\r\n")); - + $rawHeaders = rtrim($this->response['headerRaw'], "\r\n"); # Handle multiple responses e.g. with redirections (proxies too) $headerGroups = explode("\r\n\r\n", $rawHeaders); @@ -624,7 +624,7 @@ class CRemoteImage $date = strtotime($this->cache['Date']); $maxAge = $this->cache['Max-Age']; $now = time(); - + if ($imageExists && $date + $maxAge > $now) { return $this->fileName; } @@ -687,11 +687,11 @@ class CWhitelist if ($whitelist !== null) { $this->set($whitelist); } - + if (empty($item) or empty($this->whitelist)) { return false; } - + foreach ($this->whitelist as $regexp) { if (preg_match("#$regexp#", $item)) { return true; @@ -791,17 +791,17 @@ class CAsciiArt "customCharacterSet" => null, ); $default = array_merge($default, $options); - + if (!is_null($default['customCharacterSet'])) { $this->addCharacterSet('custom', $default['customCharacterSet']); $default['characterSet'] = 'custom'; } - + $this->scale = $default['scale']; $this->characters = $this->characterSet[$default['characterSet']]; $this->charCount = strlen($this->characters); $this->luminanceStrategy = $default['luminanceStrategy']; - + return $this; } @@ -822,7 +822,7 @@ class CAsciiArt $ascii = null; $incY = $this->scale; $incX = $this->scale / 2; - + for ($y = 0; $y < $height - 1; $y += $incY) { for ($x = 0; $x < $width - 1; $x += $incX) { $toX = min($x + $this->scale / 2, $width - 1); @@ -853,7 +853,7 @@ class CAsciiArt { $numPixels = ($x2 - $x1 + 1) * ($y2 - $y1 + 1); $luminance = 0; - + for ($x = $x1; $x <= $x2; $x++) { for ($y = $y1; $y <= $y2; $y++) { $rgb = imagecolorat($img, $x, $y); @@ -863,7 +863,7 @@ class CAsciiArt $luminance += $this->getLuminance($red, $green, $blue); } } - + return $luminance / $numPixels; } @@ -1545,7 +1545,7 @@ class CImage private function normalizeFileExtension($extension = null) { $extension = strtolower($extension ? $extension : $this->extension); - + if ($extension == 'jpeg') { $extension = 'jpg'; } @@ -1567,7 +1567,7 @@ class CImage if (!$this->isRemoteSourceOnWhitelist($src)) { throw new Exception("Hostname is not on whitelist for remote sources."); } - + $remote = new CRemoteImage(); $cache = $this->saveFolder . "/remote/"; @@ -2241,7 +2241,7 @@ class CImage if ($this->copyStrategy === self::RESIZE) { $copyStrat = "_rs"; } - + $width = $this->newWidth; $height = $this->newHeight; @@ -2292,7 +2292,7 @@ class CImage $subdir = ($subdir == '.') ? '_.' : $subdir; $subdir .= '_'; } - + $file = $subdir . $filename . '_' . $width . '_' . $height . $offset . $crop . $cropToFit . $fillToFit . $crop_x . $crop_y . $upscale @@ -2363,7 +2363,7 @@ class CImage if ($this->image === false) { throw new Exception("Could not load image."); } - + /* Removed v0.7.7 if (image_type_to_mime_type($this->fileType) == 'image/png') { $type = $this->getPngType(); @@ -2403,14 +2403,14 @@ class CImage public function getPngType($filename = null) { $filename = $filename ? $filename : $this->pathToImage; - + $pngType = ord(file_get_contents($filename, false, null, 25, 1)); if ($this->verbose) { $this->log("Checking png type of: " . $filename); $this->log($this->getPngTypeAsString($pngType)); } - + return $pngType; } @@ -2434,7 +2434,7 @@ class CImage $index = imagecolortransparent($this->image); $transparent = null; if ($index != -1) { - $transparent = " (transparent)"; + $transparent = " (transparent)"; } switch ($pngType) { @@ -3141,7 +3141,7 @@ class CImage $index = $this->image ? imagecolortransparent($this->image) : -1; - + if ($index != -1) { imagealphablending($img, true); @@ -3209,8 +3209,8 @@ class CImage return substr(image_type_to_extension($this->fileType), 1); } } - - + + /** * Save image. @@ -3433,7 +3433,7 @@ class CImage $this->log("Content-type: " . $mime); $this->log("Content-length: " . $size); $this->verboseOutput(); - + if (is_null($this->verboseFileName)) { exit; } @@ -3485,7 +3485,7 @@ class CImage $details['memoryPeek'] = round(memory_get_peak_usage()/1024/1024, 3) . " MB" ; $details['memoryCurrent'] = round(memory_get_usage()/1024/1024, 3) . " MB"; $details['memoryLimit'] = ini_get('memory_limit'); - + if (isset($_SERVER['REQUEST_TIME_FLOAT'])) { $details['loadTime'] = (string) round((microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']), 3) . "s"; } @@ -3642,39 +3642,21 @@ $version = "v0.7.7 (2015-10-21)"; * Display error message. * * @param string $msg to display. - * @param int $type of HTTP error to display. * * @return void */ -function errorPage($msg, $type = 500) +function errorPage($msg) { global $mode; - switch ($type) { - case 400: - $header = "400 Bad Request"; - break; - case 401: - $header = "401 Unauthorized"; - break; - case 403: - $header = "403 Forbidden"; - break; - case 404: - $header = "404 Not Found"; - break; - default: - $header = "500 Internal Server Error"; - } - - header("HTTP/1.0 $header"); + header("HTTP/1.0 500 Internal Server Error"); if ($mode == 'development') { die("[img.php] $msg"); } error_log("[img.php] $msg"); - die("HTTP/1.0 $header"); + die("HTTP/1.0 500 Internal Server Error"); } @@ -3689,7 +3671,7 @@ set_exception_handler(function ($exception) { . "

"
         . $exception->getTraceAsString()
         . "
" - , 500); + ); }); @@ -3819,7 +3801,7 @@ set_time_limit(20); ini_set('gd.jpeg_ignore_warning', 1); if (!extension_loaded('gd')) { - errorPage("Extension gd is not loaded.", 500); + errorPage("Extension gd is nod loaded."); } // Specific settings for each mode @@ -3831,7 +3813,7 @@ if ($mode == 'strict') { $verbose = false; $status = false; $verboseFile = false; - + } elseif ($mode == 'production') { error_reporting(-1); @@ -3855,7 +3837,7 @@ if ($mode == 'strict') { ini_set('log_errors', 0); } else { - errorPage("Unknown mode: $mode", 500); + errorPage("Unknown mode: $mode"); } verbose("mode = $mode"); @@ -3904,7 +3886,7 @@ if ($pwd) { } if ($pwdAlways && $passwordMatch !== true) { - errorPage("Password required and does not match or exists.", 401); + errorPage("Password required and does not match or exists."); } verbose("password match = $passwordMatch"); @@ -3928,9 +3910,9 @@ if (!$allowHotlinking) { ; // Always allow when password match verbose("Hotlinking since passwordmatch"); } elseif ($passwordMatch === false) { - errorPage("Hotlinking/leeching not allowed when password missmatch.", 401); + errorPage("Hotlinking/leeching not allowed when password missmatch."); } elseif (!$referer) { - errorPage("Hotlinking/leeching not allowed and referer is missing.", 403); + errorPage("Hotlinking/leeching not allowed and referer is missing."); } elseif (strcmp($serverName, $refererHost) == 0) { ; // Allow when serverName matches refererHost verbose("Hotlinking disallowed but serverName matches refererHost."); @@ -3941,11 +3923,11 @@ if (!$allowHotlinking) { if ($allowedByWhitelist) { verbose("Hotlinking/leeching allowed by whitelist."); } else { - errorPage("Hotlinking/leeching not allowed by whitelist. Referer: $referer.", 403); + errorPage("Hotlinking/leeching not allowed by whitelist. Referer: $referer."); } } else { - errorPage("Hotlinking/leeching not allowed.", 403); + errorPage("Hotlinking/leeching not allowed."); } } @@ -4019,7 +4001,7 @@ if (isset($shortcut) * src - the source image file. */ $srcImage = urldecode(get('src')) - or errorPage('Must set src-attribute.', 400); + or errorPage('Must set src-attribute.'); // Check for valid/invalid characters $imagePath = getConfig('image_path', __DIR__ . '/img/'); @@ -4032,7 +4014,7 @@ $dummyFilename = getConfig('dummy_filename', 'dummy'); $dummyImage = false; preg_match($validFilename, $srcImage) - or errorPage('Filename contains invalid characters.', 400); + or errorPage('Filename contains invalid characters.'); if ($dummyEnabled && $srcImage === $dummyFilename) { @@ -4053,13 +4035,13 @@ if ($dummyEnabled && $srcImage === $dummyFilename) { or errorPage( 'Source image is not a valid file, check the filename and that a matching file exists on the filesystem.' - , 404); + ); 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.' - , 500); + ); } verbose("src = $srcImage"); @@ -4108,11 +4090,11 @@ if (isset($sizes[$newWidth])) { // Support width as % of original width if ($newWidth[strlen($newWidth)-1] == '%') { is_numeric(substr($newWidth, 0, -1)) - or errorPage('Width % not numeric.', 400); + or errorPage('Width % not numeric.'); } else { is_null($newWidth) or ($newWidth > 10 && $newWidth <= $maxWidth) - or errorPage('Width out of range.', 400); + or errorPage('Width out of range.'); } verbose("new width = $newWidth"); @@ -4133,11 +4115,11 @@ if (isset($sizes[$newHeight])) { // height if ($newHeight[strlen($newHeight)-1] == '%') { is_numeric(substr($newHeight, 0, -1)) - or errorPage('Height % out of range.', 400); + or errorPage('Height % out of range.'); } else { is_null($newHeight) or ($newHeight > 10 && $newHeight <= $maxHeight) - or errorPage('Height out of range.', 400); + or errorPage('Hight out of range.'); } verbose("new height = $newHeight"); @@ -4175,7 +4157,7 @@ if ($negateAspectRatio) { is_null($aspectRatio) or is_numeric($aspectRatio) - or errorPage('Aspect ratio out of range', 400); + or errorPage('Aspect ratio out of range'); verbose("aspect ratio = $aspectRatio"); @@ -4297,7 +4279,7 @@ $qualityDefault = getConfig('jpg_quality', null); is_null($quality) or ($quality > 0 and $quality <= 100) - or errorPage('Quality out of range', 400); + or errorPage('Quality out of range'); if (is_null($quality) && !is_null($qualityDefault)) { $quality = $qualityDefault; @@ -4315,7 +4297,7 @@ $compressDefault = getConfig('png_compression', null); is_null($compress) or ($compress > 0 and $compress <= 9) - or errorPage('Compress out of range', 400); + or errorPage('Compress out of range'); if (is_null($compress) && !is_null($compressDefault)) { $compress = $compressDefault; @@ -4341,7 +4323,7 @@ $scale = get(array('scale', 's')); is_null($scale) or ($scale >= 0 and $scale <= 400) - or errorPage('Scale out of range', 400); + or errorPage('Scale out of range'); verbose("scale = $scale"); @@ -4390,7 +4372,7 @@ $rotateBefore = get(array('rotateBefore', 'rotate-before', 'rb')); is_null($rotateBefore) or ($rotateBefore >= -360 and $rotateBefore <= 360) - or errorPage('RotateBefore out of range', 400); + or errorPage('RotateBefore out of range'); verbose("rotateBefore = $rotateBefore"); @@ -4403,7 +4385,7 @@ $rotateAfter = get(array('rotateAfter', 'rotate-after', 'ra', 'rotate', 'r')); is_null($rotateAfter) or ($rotateAfter >= -360 and $rotateAfter <= 360) - or errorPage('RotateBefore out of range', 400); + or errorPage('RotateBefore out of range'); verbose("rotateAfter = $rotateAfter"); @@ -4552,13 +4534,13 @@ if ($alias && $aliasPath && $passwordMatch) { $useCache = false; is_writable($aliasPath) - or errorPage("Directory for alias is not writable.", 500); + or errorPage("Directory for alias is not writable."); preg_match($validAliasname, $alias) - or errorPage('Filename for alias contains invalid characters. Do not add extension.', 500); + or errorPage('Filename for alias contains invalid characters. Do not add extension.'); } elseif ($alias) { - errorPage('Alias is not enabled in the config file or password not matching.', 500); + errorPage('Alias is not enabled in the config file or password not matching.'); } verbose("alias = $alias"); @@ -4610,7 +4592,7 @@ if ($dummyImage === true) { $srcImage = $img->getTarget(); $imagePath = null; - + verbose("src (updated) = $srcImage"); } @@ -4669,7 +4651,7 @@ $hookBeforeCImage = getConfig('hook_before_CImage', null); if (is_callable($hookBeforeCImage)) { verbose("hookBeforeCImage activated"); - + $allConfig = $hookBeforeCImage($img, array( // Options for calculate dimensions 'newWidth' => $newWidth, @@ -4702,7 +4684,7 @@ if (is_callable($hookBeforeCImage)) { // Output format 'outputFormat' => $outputFormat, 'dpr' => $dpr, - + // Other 'postProcessing' => $postProcessing, )); diff --git a/webroot/imgp.php b/webroot/imgp.php old mode 100644 new mode 100755 index 03a45e9..08975aa --- a/webroot/imgp.php +++ b/webroot/imgp.php @@ -95,7 +95,7 @@ class CHttpGet public function setUrl($url) { $parts = parse_url($url); - + $path = ""; if (isset($parts['path'])) { $pathParts = explode('/', $parts['path']); @@ -139,7 +139,7 @@ class CHttpGet public function parseHeader() { //$header = explode("\r\n", rtrim($this->response['headerRaw'], "\r\n")); - + $rawHeaders = rtrim($this->response['headerRaw'], "\r\n"); # Handle multiple responses e.g. with redirections (proxies too) $headerGroups = explode("\r\n\r\n", $rawHeaders); @@ -624,7 +624,7 @@ class CRemoteImage $date = strtotime($this->cache['Date']); $maxAge = $this->cache['Max-Age']; $now = time(); - + if ($imageExists && $date + $maxAge > $now) { return $this->fileName; } @@ -687,11 +687,11 @@ class CWhitelist if ($whitelist !== null) { $this->set($whitelist); } - + if (empty($item) or empty($this->whitelist)) { return false; } - + foreach ($this->whitelist as $regexp) { if (preg_match("#$regexp#", $item)) { return true; @@ -791,17 +791,17 @@ class CAsciiArt "customCharacterSet" => null, ); $default = array_merge($default, $options); - + if (!is_null($default['customCharacterSet'])) { $this->addCharacterSet('custom', $default['customCharacterSet']); $default['characterSet'] = 'custom'; } - + $this->scale = $default['scale']; $this->characters = $this->characterSet[$default['characterSet']]; $this->charCount = strlen($this->characters); $this->luminanceStrategy = $default['luminanceStrategy']; - + return $this; } @@ -822,7 +822,7 @@ class CAsciiArt $ascii = null; $incY = $this->scale; $incX = $this->scale / 2; - + for ($y = 0; $y < $height - 1; $y += $incY) { for ($x = 0; $x < $width - 1; $x += $incX) { $toX = min($x + $this->scale / 2, $width - 1); @@ -853,7 +853,7 @@ class CAsciiArt { $numPixels = ($x2 - $x1 + 1) * ($y2 - $y1 + 1); $luminance = 0; - + for ($x = $x1; $x <= $x2; $x++) { for ($y = $y1; $y <= $y2; $y++) { $rgb = imagecolorat($img, $x, $y); @@ -863,7 +863,7 @@ class CAsciiArt $luminance += $this->getLuminance($red, $green, $blue); } } - + return $luminance / $numPixels; } @@ -1545,7 +1545,7 @@ class CImage private function normalizeFileExtension($extension = null) { $extension = strtolower($extension ? $extension : $this->extension); - + if ($extension == 'jpeg') { $extension = 'jpg'; } @@ -1567,7 +1567,7 @@ class CImage if (!$this->isRemoteSourceOnWhitelist($src)) { throw new Exception("Hostname is not on whitelist for remote sources."); } - + $remote = new CRemoteImage(); $cache = $this->saveFolder . "/remote/"; @@ -2241,7 +2241,7 @@ class CImage if ($this->copyStrategy === self::RESIZE) { $copyStrat = "_rs"; } - + $width = $this->newWidth; $height = $this->newHeight; @@ -2292,7 +2292,7 @@ class CImage $subdir = ($subdir == '.') ? '_.' : $subdir; $subdir .= '_'; } - + $file = $subdir . $filename . '_' . $width . '_' . $height . $offset . $crop . $cropToFit . $fillToFit . $crop_x . $crop_y . $upscale @@ -2363,7 +2363,7 @@ class CImage if ($this->image === false) { throw new Exception("Could not load image."); } - + /* Removed v0.7.7 if (image_type_to_mime_type($this->fileType) == 'image/png') { $type = $this->getPngType(); @@ -2403,14 +2403,14 @@ class CImage public function getPngType($filename = null) { $filename = $filename ? $filename : $this->pathToImage; - + $pngType = ord(file_get_contents($filename, false, null, 25, 1)); if ($this->verbose) { $this->log("Checking png type of: " . $filename); $this->log($this->getPngTypeAsString($pngType)); } - + return $pngType; } @@ -2434,7 +2434,7 @@ class CImage $index = imagecolortransparent($this->image); $transparent = null; if ($index != -1) { - $transparent = " (transparent)"; + $transparent = " (transparent)"; } switch ($pngType) { @@ -3141,7 +3141,7 @@ class CImage $index = $this->image ? imagecolortransparent($this->image) : -1; - + if ($index != -1) { imagealphablending($img, true); @@ -3209,8 +3209,8 @@ class CImage return substr(image_type_to_extension($this->fileType), 1); } } - - + + /** * Save image. @@ -3433,7 +3433,7 @@ class CImage $this->log("Content-type: " . $mime); $this->log("Content-length: " . $size); $this->verboseOutput(); - + if (is_null($this->verboseFileName)) { exit; } @@ -3485,7 +3485,7 @@ class CImage $details['memoryPeek'] = round(memory_get_peak_usage()/1024/1024, 3) . " MB" ; $details['memoryCurrent'] = round(memory_get_usage()/1024/1024, 3) . " MB"; $details['memoryLimit'] = ini_get('memory_limit'); - + if (isset($_SERVER['REQUEST_TIME_FLOAT'])) { $details['loadTime'] = (string) round((microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']), 3) . "s"; } @@ -3642,39 +3642,21 @@ $version = "v0.7.7 (2015-10-21)"; * Display error message. * * @param string $msg to display. - * @param int $type of HTTP error to display. * * @return void */ -function errorPage($msg, $type = 500) +function errorPage($msg) { global $mode; - switch ($type) { - case 400: - $header = "400 Bad Request"; - break; - case 401: - $header = "401 Unauthorized"; - break; - case 403: - $header = "403 Forbidden"; - break; - case 404: - $header = "404 Not Found"; - break; - default: - $header = "500 Internal Server Error"; - } - - header("HTTP/1.0 $header"); + header("HTTP/1.0 500 Internal Server Error"); if ($mode == 'development') { die("[img.php] $msg"); } error_log("[img.php] $msg"); - die("HTTP/1.0 $header"); + die("HTTP/1.0 500 Internal Server Error"); } @@ -3689,7 +3671,7 @@ set_exception_handler(function ($exception) { . "

"
         . $exception->getTraceAsString()
         . "
" - , 500); + ); }); @@ -3819,7 +3801,7 @@ set_time_limit(20); ini_set('gd.jpeg_ignore_warning', 1); if (!extension_loaded('gd')) { - errorPage("Extension gd is not loaded.", 500); + errorPage("Extension gd is nod loaded."); } // Specific settings for each mode @@ -3831,7 +3813,7 @@ if ($mode == 'strict') { $verbose = false; $status = false; $verboseFile = false; - + } elseif ($mode == 'production') { error_reporting(-1); @@ -3855,7 +3837,7 @@ if ($mode == 'strict') { ini_set('log_errors', 0); } else { - errorPage("Unknown mode: $mode", 500); + errorPage("Unknown mode: $mode"); } verbose("mode = $mode"); @@ -3904,7 +3886,7 @@ if ($pwd) { } if ($pwdAlways && $passwordMatch !== true) { - errorPage("Password required and does not match or exists.", 401); + errorPage("Password required and does not match or exists."); } verbose("password match = $passwordMatch"); @@ -3928,9 +3910,9 @@ if (!$allowHotlinking) { ; // Always allow when password match verbose("Hotlinking since passwordmatch"); } elseif ($passwordMatch === false) { - errorPage("Hotlinking/leeching not allowed when password missmatch.", 401); + errorPage("Hotlinking/leeching not allowed when password missmatch."); } elseif (!$referer) { - errorPage("Hotlinking/leeching not allowed and referer is missing.", 403); + errorPage("Hotlinking/leeching not allowed and referer is missing."); } elseif (strcmp($serverName, $refererHost) == 0) { ; // Allow when serverName matches refererHost verbose("Hotlinking disallowed but serverName matches refererHost."); @@ -3941,11 +3923,11 @@ if (!$allowHotlinking) { if ($allowedByWhitelist) { verbose("Hotlinking/leeching allowed by whitelist."); } else { - errorPage("Hotlinking/leeching not allowed by whitelist. Referer: $referer.", 403); + errorPage("Hotlinking/leeching not allowed by whitelist. Referer: $referer."); } } else { - errorPage("Hotlinking/leeching not allowed.", 403); + errorPage("Hotlinking/leeching not allowed."); } } @@ -4019,7 +4001,7 @@ if (isset($shortcut) * src - the source image file. */ $srcImage = urldecode(get('src')) - or errorPage('Must set src-attribute.', 400); + or errorPage('Must set src-attribute.'); // Check for valid/invalid characters $imagePath = getConfig('image_path', __DIR__ . '/img/'); @@ -4032,7 +4014,7 @@ $dummyFilename = getConfig('dummy_filename', 'dummy'); $dummyImage = false; preg_match($validFilename, $srcImage) - or errorPage('Filename contains invalid characters.', 400); + or errorPage('Filename contains invalid characters.'); if ($dummyEnabled && $srcImage === $dummyFilename) { @@ -4053,13 +4035,13 @@ if ($dummyEnabled && $srcImage === $dummyFilename) { or errorPage( 'Source image is not a valid file, check the filename and that a matching file exists on the filesystem.' - , 404); + ); 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.' - , 500); + ); } verbose("src = $srcImage"); @@ -4108,11 +4090,11 @@ if (isset($sizes[$newWidth])) { // Support width as % of original width if ($newWidth[strlen($newWidth)-1] == '%') { is_numeric(substr($newWidth, 0, -1)) - or errorPage('Width % not numeric.', 400); + or errorPage('Width % not numeric.'); } else { is_null($newWidth) or ($newWidth > 10 && $newWidth <= $maxWidth) - or errorPage('Width out of range.', 400); + or errorPage('Width out of range.'); } verbose("new width = $newWidth"); @@ -4133,11 +4115,11 @@ if (isset($sizes[$newHeight])) { // height if ($newHeight[strlen($newHeight)-1] == '%') { is_numeric(substr($newHeight, 0, -1)) - or errorPage('Height % out of range.', 400); + or errorPage('Height % out of range.'); } else { is_null($newHeight) or ($newHeight > 10 && $newHeight <= $maxHeight) - or errorPage('Height out of range.', 400); + or errorPage('Hight out of range.'); } verbose("new height = $newHeight"); @@ -4175,7 +4157,7 @@ if ($negateAspectRatio) { is_null($aspectRatio) or is_numeric($aspectRatio) - or errorPage('Aspect ratio out of range', 400); + or errorPage('Aspect ratio out of range'); verbose("aspect ratio = $aspectRatio"); @@ -4297,7 +4279,7 @@ $qualityDefault = getConfig('jpg_quality', null); is_null($quality) or ($quality > 0 and $quality <= 100) - or errorPage('Quality out of range', 400); + or errorPage('Quality out of range'); if (is_null($quality) && !is_null($qualityDefault)) { $quality = $qualityDefault; @@ -4315,7 +4297,7 @@ $compressDefault = getConfig('png_compression', null); is_null($compress) or ($compress > 0 and $compress <= 9) - or errorPage('Compress out of range', 400); + or errorPage('Compress out of range'); if (is_null($compress) && !is_null($compressDefault)) { $compress = $compressDefault; @@ -4341,7 +4323,7 @@ $scale = get(array('scale', 's')); is_null($scale) or ($scale >= 0 and $scale <= 400) - or errorPage('Scale out of range', 400); + or errorPage('Scale out of range'); verbose("scale = $scale"); @@ -4390,7 +4372,7 @@ $rotateBefore = get(array('rotateBefore', 'rotate-before', 'rb')); is_null($rotateBefore) or ($rotateBefore >= -360 and $rotateBefore <= 360) - or errorPage('RotateBefore out of range', 400); + or errorPage('RotateBefore out of range'); verbose("rotateBefore = $rotateBefore"); @@ -4403,7 +4385,7 @@ $rotateAfter = get(array('rotateAfter', 'rotate-after', 'ra', 'rotate', 'r')); is_null($rotateAfter) or ($rotateAfter >= -360 and $rotateAfter <= 360) - or errorPage('RotateBefore out of range', 400); + or errorPage('RotateBefore out of range'); verbose("rotateAfter = $rotateAfter"); @@ -4552,13 +4534,13 @@ if ($alias && $aliasPath && $passwordMatch) { $useCache = false; is_writable($aliasPath) - or errorPage("Directory for alias is not writable.", 500); + or errorPage("Directory for alias is not writable."); preg_match($validAliasname, $alias) - or errorPage('Filename for alias contains invalid characters. Do not add extension.', 500); + or errorPage('Filename for alias contains invalid characters. Do not add extension.'); } elseif ($alias) { - errorPage('Alias is not enabled in the config file or password not matching.', 500); + errorPage('Alias is not enabled in the config file or password not matching.'); } verbose("alias = $alias"); @@ -4610,7 +4592,7 @@ if ($dummyImage === true) { $srcImage = $img->getTarget(); $imagePath = null; - + verbose("src (updated) = $srcImage"); } @@ -4669,7 +4651,7 @@ $hookBeforeCImage = getConfig('hook_before_CImage', null); if (is_callable($hookBeforeCImage)) { verbose("hookBeforeCImage activated"); - + $allConfig = $hookBeforeCImage($img, array( // Options for calculate dimensions 'newWidth' => $newWidth, @@ -4702,7 +4684,7 @@ if (is_callable($hookBeforeCImage)) { // Output format 'outputFormat' => $outputFormat, 'dpr' => $dpr, - + // Other 'postProcessing' => $postProcessing, )); diff --git a/webroot/imgs.php b/webroot/imgs.php old mode 100644 new mode 100755 From 9c81286efaeae6490bc928a921ee872b7bb3a3e1 Mon Sep 17 00:00:00 2001 From: Mikael Roos Date: Wed, 2 Dec 2015 11:02:03 +0100 Subject: [PATCH 07/11] adding hook for gitter --- .travis.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.travis.yml b/.travis.yml index 84b5354..9f15485 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,9 +5,16 @@ php: - 5.6 - hhvm - nightly + - "7.0" script: - phpunit notifications: irc: "irc.freenode.org#dbwebb" + webhooks: + urls: + - https://webhooks.gitter.im/e/cce29c69604daa8a60ab + on_success: change # options: [always|never|change] default: always + on_failure: always # options: [always|never|change] default: always + on_start: never # options: [always|never|change] default: always From 8e1318c31ea0f3c72372c245e0b976ab2d85039a Mon Sep 17 00:00:00 2001 From: Mikael Roos Date: Wed, 2 Dec 2015 11:02:42 +0100 Subject: [PATCH 08/11] enable code coverage whitelist --- phpunit.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/phpunit.xml b/phpunit.xml index e406494..f24af52 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -13,4 +13,10 @@ + + + *.php + + + From 91ae49b3f37e05ea1fbd333fd2ede29dbb20d8d4 Mon Sep 17 00:00:00 2001 From: Mikael Roos Date: Wed, 2 Dec 2015 11:04:42 +0100 Subject: [PATCH 09/11] More examples on dealing with cache through bash bin/cache.bash, #129. --- REVISION.md | 1 + bin/cache.bash | 43 +++++++++++++++++++++++++------------------ 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/REVISION.md b/REVISION.md index 300976a..c64b7ea 100644 --- a/REVISION.md +++ b/REVISION.md @@ -8,6 +8,7 @@ Revision history v0.7.7* (2015-10-25) ------------------------------------- +* More examples on dealing with cache through bash `bin/cache.bash`, #129. * Added Gitter badge to README, #126. * Fix proper download url in README, #125. diff --git a/bin/cache.bash b/bin/cache.bash index 22c69e7..c5cb782 100755 --- a/bin/cache.bash +++ b/bin/cache.bash @@ -1,22 +1,17 @@ #!/bin/bash - # -# Specify the utilities used +# ls -ult list and sorts fils by its access time # -ECHO="printf" - - - # # Main, start by checking basic usage # if [ $# -lt 1 ] then - $ECHO "Usage: $0 [cache-dir]\n" + echo "Usage: $0 [cache-dir]" exit 1 elif [ ! -d "$1" ]; then - $ECHO "Usage: $0 [cache-dir]\n" - $ECHO "$1 is not a directory.\n" + echo "Usage: $0 [cache-dir]" + echo "$1 is not a directory." exit 1 fi @@ -25,12 +20,24 @@ fi # # Print out details on cache-directory # -$ECHO "Total size: $( du -sh $1 | cut -f1 )" -$ECHO "\nNumber of files: $( find $1 | wc -l )" -$ECHO "\n\nTop-5 largest files:\n" -$ECHO "$( du -s $1/* | sort -nr | head -5 )" -$ECHO "\n\nLast-5 created files:\n" -$ECHO "$( find $1/* -printf '%TY-%Tm-%Td %TH:%TM %p\n' | sort -r | head -5 )" -$ECHO "\n\nLast-5 accessed files:\n" -$ECHO "$( find $1/* -printf '%AY-%Am-%Ad %AH:%AM %f\n' | sort -r | head -5 )" -$ECHO "\n" +echo "# Size" +echo "Total size: $( du -sh $1 | cut -f1 )" +echo "Number of files: $( find $1 -type f | wc -l )" +echo "Number of dirs: $( find $1 -type d | wc -l )" +echo +echo "# Top-5 largest files/dirs:" +echo "$( du -s $1/* | sort -nr | head -5 )" +echo +echo "# Last-5 created files:" +echo "$( find $1 -type f -printf '%TY-%Tm-%Td %TH:%TM %p\n' | sort -r | head -5 )" +echo +echo "# Last-5 accessed files:" +echo "$( find $1 -type f -printf '%AY-%Am-%Ad %AH:%AM %f\n' | sort -r | head -5 )" +echo +echo "# 5 Oldest files:" +echo "$( find $1 -type f -printf '%AY-%Am-%Ad %AH:%AM %f\n' | sort | head -5 )" +echo +echo "# Files not accessed within the last 30 days" +echo "Number of files: $( find $1 -type f -atime +30 | wc -l )" +echo "Total file size: $( find $1 -type f -atime +30 -exec du {} \; | cut -f1 | paste -sd+ | bc )" +echo From b871dd7f1c2449503dfefed385a8738b158dcf3d Mon Sep 17 00:00:00 2001 From: Mikael Roos Date: Wed, 2 Dec 2015 11:05:41 +0100 Subject: [PATCH 10/11] update docs/api with phpdoc --- docs/api/classes/CAsciiArt.html | 731 +++++++++++ docs/api/classes/CHttpGet.html | 74 +- docs/api/classes/CImage.html | 1038 +++++++++++++-- docs/api/classes/CRemoteImage.html | 110 +- docs/api/classes/CWhitelist.html | 17 +- docs/api/files/CAsciiArt.html | 257 ++++ docs/api/files/CAsciiArt.php.txt | 213 +++ docs/api/files/CHttpGet.html | 13 +- docs/api/files/CHttpGet.php.txt | 54 +- docs/api/files/CImage.html | 13 +- docs/api/files/CImage.php.txt | 565 ++++++-- docs/api/files/CRemoteImage.html | 13 +- docs/api/files/CRemoteImage.php.txt | 101 +- docs/api/files/CWhitelist.html | 13 +- docs/api/files/CWhitelist.php.txt | 14 +- docs/api/files/autoload.html | 13 +- docs/api/files/autoload.php.txt | 2 +- docs/api/files/webroot.img.html | 15 +- docs/api/files/webroot.img_config.html | 13 +- docs/api/files/webroot/img.php.txt | 1167 +++++++++++++++++ docs/api/files/webroot/img_config.php.txt | 386 ++++++ docs/api/graphs/class.html | 6 +- docs/api/graphs/classes.svg | 29 +- docs/api/index.html | 19 +- docs/api/namespaces/default.html | 19 +- ...-file_5de178c5dafcaff40d31e6fe8bec9eea.dat | Bin 44103 -> 48283 bytes ...-file_58c9e20d7971fb3461feadcf8052d7c6.dat | Bin 39662 -> 34882 bytes ...-file_05104b5f33216f058e4b600e59ccee4e.dat | Bin 253004 -> 297123 bytes ...-file_ace2bb5eac6f81a3a5d8d5eeb2b59685.dat | Bin 0 -> 33990 bytes ...-file_73f6e60ef59c0c30ffc560b4da7243ca.dat | Bin 13903 -> 13188 bytes ...-file_2c624667a65767f32365565ca6d89fea.dat | Bin 30835 -> 36436 bytes ...-file_ec58a87628ba00fb2321bc6cdb7d54b4.dat | Bin 10977 -> 11016 bytes ...-file_83ad6bd4885732fd14b9d8709d592efd.dat | Bin 3176 -> 2758 bytes docs/api/reports/deprecated.html | 6 +- docs/api/reports/errors.html | 161 ++- docs/api/reports/markers.html | 920 +------------ 36 files changed, 4492 insertions(+), 1490 deletions(-) create mode 100644 docs/api/classes/CAsciiArt.html create mode 100644 docs/api/files/CAsciiArt.html create mode 100644 docs/api/files/CAsciiArt.php.txt create mode 100644 docs/api/files/webroot/img.php.txt create mode 100644 docs/api/files/webroot/img_config.php.txt create mode 100644 docs/api/phpdoc-cache-aa/phpdoc-cache-file_ace2bb5eac6f81a3a5d8d5eeb2b59685.dat diff --git a/docs/api/classes/CAsciiArt.html b/docs/api/classes/CAsciiArt.html new file mode 100644 index 0000000..17073e8 --- /dev/null +++ b/docs/api/classes/CAsciiArt.html @@ -0,0 +1,731 @@ + + + + + + CImage API Documentaion + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+
+
+
+ + + +

\CAsciiArt

+

Create an ASCII version of an image.

+ + + +
+

Summary

+
+
+ Methods +
+
+ Properties +
+
+ Constants +
+
+
+
+ __construct()
+ addCharacterSet()
+ setOptions()
+ createFromFile()
+ luminanceAreaAverage()
+ getLuminance()
+ luminance2character()
+
+
+ No public properties found +
+
+ No constants found +
+
+
+
+ No protected methods found +
+
+ No protected properties found +
+
+ N/A +
+
+
+
+ No private methods found +
+
+ $characterSet
+ $characters
+ $charCount
+ $scale
+ $luminanceStrategy
+
+
+ N/A +
+
+
+
+ +
+ + + +
+
+

Properties

+
+ +
+ +
+
+ +
+

$characterSet

+
$characterSet : 
+

Character set to use.

+ + +

Type

+ +
+
+ +
+ +
+
+ +
+

$characters

+
$characters : 
+

Current character set.

+ + +

Type

+ +
+
+ +
+ +
+
+ +
+

$charCount

+
$charCount : 
+

Length of current character set.

+ + +

Type

+ +
+
+ +
+ +
+
+ +
+

$scale

+
$scale : 
+

Scale of the area to swap to a character.

+ + +

Type

+ +
+
+ +
+ +
+
+ +
+

$luminanceStrategy

+
$luminanceStrategy : 
+

Strategy to calculate luminance.

+ + +

Type

+ +
+
+ +
+ + + +
+

Methods

+ +
+ +
+
+ +
+

__construct()

+ +
__construct() 
+

Constructor which sets default options.

+ + + + + +
+
+ +
+ +
+
+ +
+

addCharacterSet()

+ +
addCharacterSet(string  $key, string  $value) : $this
+

Add a custom character set.

+ + +

Parameters

+ + + + + + + + + + + +
string$key

for the character set.

string$value

for the character set.

+ + +

Returns

+ $this + +
+
+ +
+ +
+
+ +
+

setOptions()

+ +
setOptions(array  $options = array()) : $this
+

Set options for processing, defaults are available.

+ + +

Parameters

+ + + + + + +
array$options

to use as default settings.

+ + +

Returns

+ $this + +
+
+ +
+ +
+
+ +
+

createFromFile()

+ +
createFromFile(string  $filename) : string
+

Create an Ascii image from an image file.

+ + +

Parameters

+ + + + + + +
string$filename

of the image to use.

+ + +

Returns

+ string + —

$ascii with the ASCII image.

+ +
+
+ +
+ +
+
+ +
+

luminanceAreaAverage()

+ +
luminanceAreaAverage(string  $img, integer  $x1, integer  $y1, integer  $x2, integer  $y2) : integer
+

Get the luminance from a region of an image using average color value.

+ + +

Parameters

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
string$img

the image.

integer$x1

the area to get pixels from.

integer$y1

the area to get pixels from.

integer$x2

the area to get pixels from.

integer$y2

the area to get pixels from.

+ + +

Returns

+ integer + —

$luminance with a value between 0 and 100.

+ +
+
+ +
+ +
+
+ +
+

getLuminance()

+ +
getLuminance(integer  $red, integer  $green, integer  $blue) : float
+

Calculate luminance value with different strategies.

+ + +

Parameters

+ + + + + + + + + + + + + + + + +
integer$red

The color red.

integer$green

The color green.

integer$blue

The color blue.

+ + +

Returns

+ float + —

$luminance with a value between 0 and 1.

+ +
+
+ +
+ +
+
+ +
+

luminance2character()

+ +
luminance2character(  $luminance) : string
+

Translate the luminance value to a character.

+ + +

Parameters

+ + + + + + +
$luminance
+ + +

Returns

+ string + —

with the ascii character.

+ +
+
+ +
+ +
+
+ + + + +
+ + + diff --git a/docs/api/classes/CHttpGet.html b/docs/api/classes/CHttpGet.html index a456b80..ea8f9c1 100644 --- a/docs/api/classes/CHttpGet.html +++ b/docs/api/classes/CHttpGet.html @@ -106,12 +106,12 @@