1
0
mirror of https://github.com/mosbth/cimage.git synced 2025-08-05 15:47:30 +02:00

Adding support for AsciiArt of an image.

This commit is contained in:
Mikael Roos
2015-09-01 16:45:10 +02:00
parent b65b420313
commit 2959f11f33
4 changed files with 323 additions and 2 deletions

View File

@@ -334,6 +334,13 @@ class CImage
/*
* output to ascii can take som options as an array.
*/
private $asciiOptions = array();
/**
* Properties, the class is mutable and the method setOptions()
* decides (partly) what properties are created.
@@ -2250,6 +2257,10 @@ class CImage
header('Content-type: application/json');
echo $this->json($file);
exit;
} elseif ($format == 'ascii') {
header('Content-type: text/plain');
echo $this->ascii($file);
exit;
}
$this->log("Outputting image: $file");
@@ -2341,6 +2352,38 @@ class CImage
/**
* Set options for creating ascii version of image.
*
* @param array $options empty to use default or set options to change.
*
* @return void.
*/
public function setAsciiOptions($options = array())
{
$this->asciiOptions = $options;
}
/**
* Create an ASCII version from the image details.
*
* @param string $file the file to output.
*
* @return string ASCII representation of the image.
*/
public function ascii($file = null)
{
$file = $file ? $file : $this->cacheFileName;
$asciiArt = new CAsciiArt();
$asciiArt->setOptions($this->asciiOptions);
return $asciiArt->createFromFile($file);
}
/**
* Log an event if verbose mode.
*