From 37b39fbecf51345632cd2edcbbddc3022e6d28ff Mon Sep 17 00:00:00 2001 From: Mikael Roos Date: Tue, 20 Oct 2015 10:04:37 +0200 Subject: [PATCH] Add extra fileds to json-response, #114. --- CImage.php | 57 ++++++++++++++++++++++++++++++++++++++++++++--------- REVISION.md | 3 ++- 2 files changed, 50 insertions(+), 10 deletions(-) diff --git a/CImage.php b/CImage.php index aa84013..797bb27 100644 --- a/CImage.php +++ b/CImage.php @@ -1430,44 +1430,74 @@ class CImage /** * Get the type of PNG image. * + * @param string $filename to use instead of default. + * * @return int as the type of the png-image * */ - private function getPngType() + public function getPngType($filename = null) { - $pngType = ord(file_get_contents($this->pathToImage, false, null, 25, 1)); + $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; + } + + + + /** + * Get the type of PNG image as a verbose string. + * + * @param integer $type to use, default is to check the type. + * @param string $filename to use instead of default. + * + * @return int as the type of the png-image + * + */ + private function getPngTypeAsString($pngType = null, $filename = null) + { + if ($filename || !$pngType) { + $pngType = $this->getPngType($filename); + } switch ($pngType) { case self::PNG_GREYSCALE: - $this->log("PNG is type 0, Greyscale."); + $text = "PNG is type 0, Greyscale."; break; case self::PNG_RGB: - $this->log("PNG is type 2, RGB"); + $text = "PNG is type 2, RGB"; break; case self::PNG_RGB_PALETTE: - $this->log("PNG is type 3, RGB with palette"); + $text = "PNG is type 3, RGB with palette"; break; case self::PNG_GREYSCALE_ALPHA: - $this->Log("PNG is type 4, Greyscale with alpha channel"); + $text = "PNG is type 4, Greyscale with alpha channel"; break; case self::PNG_RGB_ALPHA: - $this->Log("PNG is type 6, RGB with alpha channel (PNG 32-bit)"); + $text = "PNG is type 6, RGB with alpha channel (PNG 32-bit)"; break; default: - $this->Log("PNG is UNKNOWN type, is it really a PNG image?"); + $text = "PNG is UNKNOWN type, is it really a PNG image?"; } - return $pngType; + return $text; } + /** * Calculate number of colors in an image. * @@ -2425,6 +2455,15 @@ class CImage $details['aspectRatio'] = round($this->width / $this->height, 3); $details['size'] = filesize($file); $details['colors'] = $this->colorsTotal($this->image); + $details['includedFiles'] = count(get_included_files()); + $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 ($details['mimeType'] == 'image/png') { + $details['pngTypeSource'] = $this->getPngTypeAsString(); + $details['pngTypeCache'] = $this->getPngTypeAsString(null, $this->cacheFileName); + } $options = null; if (defined("JSON_PRETTY_PRINT") && defined("JSON_UNESCAPED_SLASHES")) { diff --git a/REVISION.md b/REVISION.md index 13dbd91..d356939 100644 --- a/REVISION.md +++ b/REVISION.md @@ -5,9 +5,10 @@ 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.6* (2015-10-18) +v0.7.6* (2015-10-20) ------------------------------------- +* Add extra fileds to json-response, #114. * Add header for Content-Length, #111. * Add check for postprocessing tools in path in `webroot/check_system.php`, #104.