1
0
mirror of https://github.com/mosbth/cimage.git synced 2025-08-12 19:14:01 +02:00

Add extra fileds to json-response, #114.

This commit is contained in:
Mikael Roos
2015-10-20 10:04:37 +02:00
parent 553d2f3db1
commit 37b39fbecf
2 changed files with 50 additions and 10 deletions

View File

@@ -1430,37 +1430,20 @@ class CImage
/** /**
* Get the type of PNG image. * Get the type of PNG image.
* *
* @param string $filename to use instead of default.
*
* @return int as the type of the png-image * @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;
switch ($pngType) { $pngType = ord(file_get_contents($filename, false, null, 25, 1));
case self::PNG_GREYSCALE: if ($this->verbose) {
$this->log("PNG is type 0, Greyscale."); $this->log("Checking png type of: " . $filename);
break; $this->log($this->getPngTypeAsString($pngType));
case self::PNG_RGB:
$this->log("PNG is type 2, RGB");
break;
case self::PNG_RGB_PALETTE:
$this->log("PNG is type 3, RGB with palette");
break;
case self::PNG_GREYSCALE_ALPHA:
$this->Log("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)");
break;
default:
$this->Log("PNG is UNKNOWN type, is it really a PNG image?");
} }
return $pngType; return $pngType;
@@ -1468,6 +1451,53 @@ class CImage
/**
* 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:
$text = "PNG is type 0, Greyscale.";
break;
case self::PNG_RGB:
$text = "PNG is type 2, RGB";
break;
case self::PNG_RGB_PALETTE:
$text = "PNG is type 3, RGB with palette";
break;
case self::PNG_GREYSCALE_ALPHA:
$text = "PNG is type 4, Greyscale with alpha channel";
break;
case self::PNG_RGB_ALPHA:
$text = "PNG is type 6, RGB with alpha channel (PNG 32-bit)";
break;
default:
$text = "PNG is UNKNOWN type, is it really a PNG image?";
}
return $text;
}
/** /**
* Calculate number of colors in an image. * Calculate number of colors in an image.
* *
@@ -2425,6 +2455,15 @@ class CImage
$details['aspectRatio'] = round($this->width / $this->height, 3); $details['aspectRatio'] = round($this->width / $this->height, 3);
$details['size'] = filesize($file); $details['size'] = filesize($file);
$details['colors'] = $this->colorsTotal($this->image); $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; $options = null;
if (defined("JSON_PRETTY_PRINT") && defined("JSON_UNESCAPED_SLASHES")) { if (defined("JSON_PRETTY_PRINT") && defined("JSON_UNESCAPED_SLASHES")) {

View File

@@ -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) [![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 header for Content-Length, #111.
* Add check for postprocessing tools in path in `webroot/check_system.php`, #104. * Add check for postprocessing tools in path in `webroot/check_system.php`, #104.