Skip to content

Commit

Permalink
Merge pull request #478 from bcit-ci/feature/image
Browse files Browse the repository at this point in the history
New Image Handling
  • Loading branch information
lonnieezell authored May 26, 2017
2 parents 31748eb + 04de7b8 commit b0e2b7d
Show file tree
Hide file tree
Showing 17 changed files with 2,265 additions and 69 deletions.
31 changes: 31 additions & 0 deletions application/Config/Images.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php namespace Config;

use CodeIgniter\Config\BaseConfig;

class Images extends BaseConfig
{
/**
* Default handler used if no other handler is specified.
*
* @var string
*/
public $defaultHandler = 'gd';

/**
* The path to the image library.
* Required for ImageMagick, GraphicsMagick, or NetPBM.
*
* @var string
*/
public $libraryPath = '/usr/local/bin/convert';

/**
* The available handler classes.
*
* @var array
*/
public $handlers = [
'gd' => \CodeIgniter\Images\Handlers\GDHandler::class,
'imagick' => \CodeIgniter\Images\Handlers\ImageMagickHandler::class,
];
}
39 changes: 39 additions & 0 deletions application/Controllers/Checks.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,44 @@ public function catch()
echo $body;
}

public function redirect()
{
redirect('/checks/model');
}

public function image()
{
$info = Services::image('imagick')
->withFile("/Users/kilishan/Documents/BobHeader.jpg")
->getFile()
->getProperties(true);

dd($info);

$images = Services::image('imagick')
->getVersion();
// ->withFile("/Users/kilishan/Documents/BobHeader.jpg")
// ->resize(500, 100, true)
// ->crop(200, 75, 20, 0, false)
// ->rotate(90)
// ->save('/Users/kilishan/temp.jpg');

// $images = Services::image('imagick')
// ->withFile("/Users/kilishan/Documents/BobHeader.jpg")
// ->fit(500, 100, 'bottom-left')
// ->text('Bob is Back!', [
// 'fontPath' => '/Users/kilishan/Downloads/Calibri.ttf',
// 'fontSize' => 40,
// 'padding' => 0,
// 'opacity' => 0.5,
// 'vAlign' => 'top',
// 'hAlign' => 'right',
// 'withShadow' => true,
// ])
// ->save('/Users/kilishan/temp.jpg', 100);


ddd($images);
}

}
47 changes: 47 additions & 0 deletions system/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -861,3 +861,50 @@ function slash_item($item)
}
}
//--------------------------------------------------------------------

if ( ! function_exists('function_usable'))
{
/**
* Function usable
*
* Executes a function_exists() check, and if the Suhosin PHP
* extension is loaded - checks whether the function that is
* checked might be disabled in there as well.
*
* This is useful as function_exists() will return FALSE for
* functions disabled via the *disable_functions* php.ini
* setting, but not for *suhosin.executor.func.blacklist* and
* *suhosin.executor.disable_eval*. These settings will just
* terminate script execution if a disabled function is executed.
*
* The above described behavior turned out to be a bug in Suhosin,
* but even though a fix was commited for 0.9.34 on 2012-02-12,
* that version is yet to be released. This function will therefore
* be just temporary, but would probably be kept for a few years.
*
* @link http://www.hardened-php.net/suhosin/
* @param string $function_name Function to check for
* @return bool TRUE if the function exists and is safe to call,
* FALSE otherwise.
*/
function function_usable($function_name)
{
static $_suhosin_func_blacklist;

if (function_exists($function_name))
{
if ( ! isset($_suhosin_func_blacklist))
{
$_suhosin_func_blacklist = extension_loaded('suhosin')
? explode(',', trim(ini_get('suhosin.executor.func.blacklist')))
: array();
}

return ! in_array($function_name, $_suhosin_func_blacklist, TRUE);
}

return FALSE;
}
}

//--------------------------------------------------------------------
138 changes: 69 additions & 69 deletions system/Config/AutoloadConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,76 +110,76 @@ public function __construct()
* ];
*/
$this->classmap = [
'CodeIgniter\CodeIgniter' => BASEPATH.'CodeIgniter.php',
'CodeIgniter\CLI\CLI' => BASEPATH.'CLI/CLI.php',
'CodeIgniter\Loader' => BASEPATH.'Loader.php',
'CodeIgniter\Cache\CacheFactory' => BASEPATH.'Cache/CacheFactory.php',
'CodeIgniter\Cache\CacheInterface' => BASEPATH.'Cache/CacheInterface.php',
'CodeIgniter\Cache\Handlers\DummyHandler' => BASEPATH.'Cache/Handlers/DummyHandler.php',
'CodeIgniter\Cache\Handlers\FileHandler' => BASEPATH.'Cache/Handlers/FileHandler.php',
'CodeIgniter\Cache\Handlers\MemcachedHandler' => BASEPATH.'Cache/Handlers/MemcachedHandler.php',
'CodeIgniter\Cache\Handlers\PredisHandler' => BASEPATH.'Cache/Handlers/PredisHandler.php',
'CodeIgniter\Cache\Handlers\RedisHandler' => BASEPATH.'Cache/Handlers/RedisHandler.php',
'CodeIgniter\Cache\Handlers\WincacheHandler' => BASEPATH.'Cache/Handlers/WincacheHandler.php',
'CodeIgniter\Controller' => BASEPATH.'Controller.php',
'CodeIgniter\Config\AutoloadConfig' => BASEPATH.'Config/Autoload.php',
'CodeIgniter\Config\BaseConfig' => BASEPATH.'Config/BaseConfig.php',
'CodeIgniter\Config\Database' => BASEPATH.'Config/Database.php',
'CodeIgniter\Config\Database\Connection' => BASEPATH.'Config/Database/Connection.php',
'CodeIgniter\Config\Database\Connection\MySQLi' => BASEPATH.'Config/Database/Connection/MySQLi.php',
'CodeIgniter\Config\DotEnv' => BASEPATH.'Config/DotEnv.php',
'CodeIgniter\Database\BaseBuilder' => BASEPATH.'Database/BaseBuilder.php',
'CodeIgniter\Database\BaseConnection' => BASEPATH.'Database/BaseConnection.php',
'CodeIgniter\Database\BaseResult' => BASEPATH.'Database/BaseResult.php',
'CodeIgniter\Database\Config' => BASEPATH.'Database/Config.php',
'CodeIgniter\Database\ConnectionInterface' => BASEPATH.'Database/ConnectionInterface.php',
'CodeIgniter\Database\Database' => BASEPATH.'Database/Database.php',
'CodeIgniter\Database\Query' => BASEPATH.'Database/Query.php',
'CodeIgniter\Database\QueryInterface' => BASEPATH.'Database/QueryInterface.php',
'CodeIgniter\Database\ResultInterface' => BASEPATH.'Database/ResultInterface.php',
'CodeIgniter\Database\Migration' => BASEPATH.'Database/Migration.php',
'CodeIgniter\Database\MigrationRunner' => BASEPATH.'Database/MigrationRunner.php',
'CodeIgniter\Debug\Exceptions' => BASEPATH.'Debug/Exceptions.php',
'CodeIgniter\Debug\Timer' => BASEPATH.'Debug/Timer.php',
'CodeIgniter\Debug\Iterator' => BASEPATH.'Debug/Iterator.php',
'CodeIgniter\Events\Events' => BASEPATH.'Events/Events.php',
'CodeIgniter\HTTP\CLIRequest' => BASEPATH.'HTTP/CLIRequest.php',
'CodeIgniter\HTTP\ContentSecurityPolicy' => BASEPATH.'HTTP/ContentSecurityPolicy.php',
'CodeIgniter\HTTP\CURLRequest' => BASEPATH.'HTTP/CURLRequest.php',
'CodeIgniter\HTTP\IncomingRequest' => BASEPATH.'HTTP/IncomingRequest.php',
'CodeIgniter\HTTP\Message' => BASEPATH.'HTTP/Message.php',
'CodeIgniter\HTTP\Negotiate' => BASEPATH.'HTTP/Negotiate.php',
'CodeIgniter\HTTP\Request' => BASEPATH.'HTTP/Request.php',
'CodeIgniter\HTTP\RequestInterface' => BASEPATH.'HTTP/RequestInterface.php',
'CodeIgniter\HTTP\Response' => BASEPATH.'HTTP/Response.php',
'CodeIgniter\HTTP\ResponseInterface' => BASEPATH.'HTTP/ResponseInterface.php',
'CodeIgniter\HTTP\URI' => BASEPATH.'HTTP/URI.php',
'CodeIgniter\Log\Logger' => BASEPATH.'Log/Logger.php',
'Psr\Log\LoggerAwareInterface' => BASEPATH.'ThirdParty/PSR/Log/LoggerAwareInterface.php',
'Psr\Log\LoggerAwareTrait' => BASEPATH.'ThirdParty/PSR/Log/LoggerAwareTrait.php',
'Psr\Log\LoggerInterface' => BASEPATH.'ThirdParty/PSR/Log/LoggerInterface.php',
'Psr\Log\LogLevel' => BASEPATH.'ThirdParty/PSR/Log/LogLevel.php',
'CodeIgniter\Log\Handlers\BaseHandler' => BASEPATH.'Log/Handlers/BaseHandler.php',
'CodeIgniter\Log\Handlers\ChromeLoggerHandler' => BASEPATH.'Log/Handlers/ChromeLoggerHandler.php',
'CodeIgniter\Log\Handlers\FileHandler' => BASEPATH.'Log/Handlers/FileHandler.php',
'CodeIgniter\Log\Handlers\HandlerInterface' => BASEPATH.'Log/Handlers/HandlerInterface.php',
'CodeIgniter\Router\RouteCollection' => BASEPATH.'Router/RouteCollection.php',
'CodeIgniter\Router\RouteCollectionInterface' => BASEPATH.'Router/RouteCollectionInterface.php',
'CodeIgniter\Router\Router' => BASEPATH.'Router/Router.php',
'CodeIgniter\Router\RouterInterface' => BASEPATH.'Router/RouterInterface.php',
'CodeIgniter\Security\Security' => BASEPATH.'Security/Security.php',
'CodeIgniter\Session\Session' => BASEPATH.'Session/Session.php',
'CodeIgniter\Session\SessionInterface' => BASEPATH.'Session/SessionInterface.php',
'CodeIgniter\Session\Handlers\BaseHandler' => BASEPATH.'Session/Handlers/BaseHandler.php',
'CodeIgniter\Session\Handlers\FileHandler' => BASEPATH.'Session/Handlers/FileHandler.php',
'CodeIgniter\Session\Handlers\MemcachedHandler' => BASEPATH.'Session/Handlers/MemcachedHandler.php',
'CodeIgniter\Session\Handlers\RedisHandler' => BASEPATH.'Session/Handlers/RedisHandler.php',
'CodeIgniter\View\RendererInterface' => BASEPATH.'View/RendererInterface.php',
'CodeIgniter\View\View' => BASEPATH.'View/View.php',
'CodeIgniter\View\Parser' => BASEPATH.'View/Parser.php',
'CodeIgniter\View\Cell' => BASEPATH.'View/Cell.php',
// 'CodeIgniter\CodeIgniter' => BASEPATH.'CodeIgniter.php',
// 'CodeIgniter\CLI\CLI' => BASEPATH.'CLI/CLI.php',
// 'CodeIgniter\Loader' => BASEPATH.'Loader.php',
// 'CodeIgniter\Cache\CacheFactory' => BASEPATH.'Cache/CacheFactory.php',
// 'CodeIgniter\Cache\CacheInterface' => BASEPATH.'Cache/CacheInterface.php',
// 'CodeIgniter\Cache\Handlers\DummyHandler' => BASEPATH.'Cache/Handlers/DummyHandler.php',
// 'CodeIgniter\Cache\Handlers\FileHandler' => BASEPATH.'Cache/Handlers/FileHandler.php',
// 'CodeIgniter\Cache\Handlers\MemcachedHandler' => BASEPATH.'Cache/Handlers/MemcachedHandler.php',
// 'CodeIgniter\Cache\Handlers\PredisHandler' => BASEPATH.'Cache/Handlers/PredisHandler.php',
// 'CodeIgniter\Cache\Handlers\RedisHandler' => BASEPATH.'Cache/Handlers/RedisHandler.php',
// 'CodeIgniter\Cache\Handlers\WincacheHandler' => BASEPATH.'Cache/Handlers/WincacheHandler.php',
// 'CodeIgniter\Controller' => BASEPATH.'Controller.php',
// 'CodeIgniter\Config\AutoloadConfig' => BASEPATH.'Config/Autoload.php',
// 'CodeIgniter\Config\BaseConfig' => BASEPATH.'Config/BaseConfig.php',
// 'CodeIgniter\Config\Database' => BASEPATH.'Config/Database.php',
// 'CodeIgniter\Config\Database\Connection' => BASEPATH.'Config/Database/Connection.php',
// 'CodeIgniter\Config\Database\Connection\MySQLi' => BASEPATH.'Config/Database/Connection/MySQLi.php',
// 'CodeIgniter\Config\DotEnv' => BASEPATH.'Config/DotEnv.php',
// 'CodeIgniter\Database\BaseBuilder' => BASEPATH.'Database/BaseBuilder.php',
// 'CodeIgniter\Database\BaseConnection' => BASEPATH.'Database/BaseConnection.php',
// 'CodeIgniter\Database\BaseResult' => BASEPATH.'Database/BaseResult.php',
// 'CodeIgniter\Database\Config' => BASEPATH.'Database/Config.php',
// 'CodeIgniter\Database\ConnectionInterface' => BASEPATH.'Database/ConnectionInterface.php',
// 'CodeIgniter\Database\Database' => BASEPATH.'Database/Database.php',
// 'CodeIgniter\Database\Query' => BASEPATH.'Database/Query.php',
// 'CodeIgniter\Database\QueryInterface' => BASEPATH.'Database/QueryInterface.php',
// 'CodeIgniter\Database\ResultInterface' => BASEPATH.'Database/ResultInterface.php',
// 'CodeIgniter\Database\Migration' => BASEPATH.'Database/Migration.php',
// 'CodeIgniter\Database\MigrationRunner' => BASEPATH.'Database/MigrationRunner.php',
// 'CodeIgniter\Debug\Exceptions' => BASEPATH.'Debug/ImageException.php',
// 'CodeIgniter\Debug\Timer' => BASEPATH.'Debug/Timer.php',
// 'CodeIgniter\Debug\Iterator' => BASEPATH.'Debug/Iterator.php',
// 'CodeIgniter\Events\Events' => BASEPATH.'Events/Events.php',
// 'CodeIgniter\HTTP\CLIRequest' => BASEPATH.'HTTP/CLIRequest.php',
// 'CodeIgniter\HTTP\ContentSecurityPolicy' => BASEPATH.'HTTP/ContentSecurityPolicy.php',
// 'CodeIgniter\HTTP\CURLRequest' => BASEPATH.'HTTP/CURLRequest.php',
// 'CodeIgniter\HTTP\IncomingRequest' => BASEPATH.'HTTP/IncomingRequest.php',
// 'CodeIgniter\HTTP\Message' => BASEPATH.'HTTP/Message.php',
// 'CodeIgniter\HTTP\Negotiate' => BASEPATH.'HTTP/Negotiate.php',
// 'CodeIgniter\HTTP\Request' => BASEPATH.'HTTP/Request.php',
// 'CodeIgniter\HTTP\RequestInterface' => BASEPATH.'HTTP/RequestInterface.php',
// 'CodeIgniter\HTTP\Response' => BASEPATH.'HTTP/Response.php',
// 'CodeIgniter\HTTP\ResponseInterface' => BASEPATH.'HTTP/ResponseInterface.php',
// 'CodeIgniter\HTTP\URI' => BASEPATH.'HTTP/URI.php',
// 'CodeIgniter\Log\Logger' => BASEPATH.'Log/Logger.php',
// 'Psr\Log\LoggerAwareInterface' => BASEPATH.'ThirdParty/PSR/Log/LoggerAwareInterface.php',
// 'Psr\Log\LoggerAwareTrait' => BASEPATH.'ThirdParty/PSR/Log/LoggerAwareTrait.php',
// 'Psr\Log\LoggerInterface' => BASEPATH.'ThirdParty/PSR/Log/LoggerInterface.php',
// 'Psr\Log\LogLevel' => BASEPATH.'ThirdParty/PSR/Log/LogLevel.php',
// 'CodeIgniter\Log\Handlers\BaseHandler' => BASEPATH.'Log/Handlers/BaseHandler.php',
// 'CodeIgniter\Log\Handlers\ChromeLoggerHandler' => BASEPATH.'Log/Handlers/ChromeLoggerHandler.php',
// 'CodeIgniter\Log\Handlers\FileHandler' => BASEPATH.'Log/Handlers/FileHandler.php',
// 'CodeIgniter\Log\Handlers\HandlerInterface' => BASEPATH.'Log/Handlers/HandlerInterface.php',
// 'CodeIgniter\Router\RouteCollection' => BASEPATH.'Router/RouteCollection.php',
// 'CodeIgniter\Router\RouteCollectionInterface' => BASEPATH.'Router/RouteCollectionInterface.php',
// 'CodeIgniter\Router\Router' => BASEPATH.'Router/Router.php',
// 'CodeIgniter\Router\RouterInterface' => BASEPATH.'Router/RouterInterface.php',
// 'CodeIgniter\Security\Security' => BASEPATH.'Security/Security.php',
// 'CodeIgniter\Session\Session' => BASEPATH.'Session/Session.php',
// 'CodeIgniter\Session\SessionInterface' => BASEPATH.'Session/SessionInterface.php',
// 'CodeIgniter\Session\Handlers\BaseHandler' => BASEPATH.'Session/Handlers/BaseHandler.php',
// 'CodeIgniter\Session\Handlers\FileHandler' => BASEPATH.'Session/Handlers/FileHandler.php',
// 'CodeIgniter\Session\Handlers\MemcachedHandler' => BASEPATH.'Session/Handlers/MemcachedHandler.php',
// 'CodeIgniter\Session\Handlers\RedisHandler' => BASEPATH.'Session/Handlers/RedisHandler.php',
// 'CodeIgniter\View\RendererInterface' => BASEPATH.'View/RendererInterface.php',
// 'CodeIgniter\View\View' => BASEPATH.'View/View.php',
// 'CodeIgniter\View\Parser' => BASEPATH.'View/Parser.php',
// 'CodeIgniter\View\Cell' => BASEPATH.'View/Cell.php',
'Zend\Escaper\Escaper' => BASEPATH.'ThirdParty/ZendEscaper/Escaper.php',
'CodeIgniter\Log\TestLogger' => BASEPATH.'../tests/_support/Log/TestLogger.php',
// 'CodeIgniter\Log\TestLogger' => BASEPATH.'../tests/_support/Log/TestLogger.php',
'CIDatabaseTestCase' => BASEPATH.'../tests/_support/CIDatabaseTestCase.php'
];
}
Expand Down
27 changes: 27 additions & 0 deletions system/Config/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,33 @@ public static function filters($config = null, $getShared = true)

//--------------------------------------------------------------------

/**
* Acts as a factory for ImageHandler classes and returns an instance
* of the handler. Used like Services::image()->withFile($path)->rotate(90)->save();
*/
public static function image(string $handler=null, $config = null, $getShared = true)
{
if ($getShared)
{
return self::getSharedInstance('image', $handler, $config);
}

if (empty($config))
{
$config = new \Config\Images();
}

$handler = is_null($handler)
? $config->defaultHandler
: $handler;

$class = $config->handlers[$handler];

return new $class($config);
}

//--------------------------------------------------------------------

/**
* The Iterator class provides a simple way of looping over a function
* and timing the results and memory usage. Used when debugging and
Expand Down
3 changes: 3 additions & 0 deletions system/Images/Exceptions/ImageException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php namespace CodeIgniter\Images\Exceptions;

class ImageException extends \RuntimeException{}
Loading

0 comments on commit b0e2b7d

Please sign in to comment.