1 <?php
 2 /**
 3  * @package     Joomla.Platform
 4  * @subpackage  Image
 5  *
 6  * @copyright   Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
 7  * @license     GNU General Public License version 2 or later; see LICENSE
 8  */
 9 
10 defined('JPATH_PLATFORM') or die;
11 
12 /**
13  * Class to manipulate an image.
14  *
15  * @since  11.3
16  */
17 abstract class JImageFilter
18 {
19     /**
20      * @var    resource  The image resource handle.
21      * @since  11.3
22      */
23     protected $handle;
24 
25     /**
26      * Class constructor.
27      *
28      * @param   resource  $handle  The image resource on which to apply the filter.
29      *
30      * @since   11.3
31      * @throws  InvalidArgumentException
32      * @throws  RuntimeException
33      */
34     public function __construct($handle)
35     {
36         // Verify that image filter support for PHP is available.
37         if (!function_exists('imagefilter'))
38         {
39             // @codeCoverageIgnoreStart
40             JLog::add('The imagefilter function for PHP is not available.', JLog::ERROR);
41             throw new RuntimeException('The imagefilter function for PHP is not available.');
42 
43             // @codeCoverageIgnoreEnd
44         }
45 
46         // Make sure the file handle is valid.
47         if (!is_resource($handle) || (get_resource_type($handle) != 'gd'))
48         {
49             JLog::add('The image handle is invalid for the image filter.', JLog::ERROR);
50             throw new InvalidArgumentException('The image handle is invalid for the image filter.');
51         }
52 
53         $this->handle = $handle;
54     }
55 
56     /**
57      * Method to apply a filter to an image resource.
58      *
59      * @param   array  $options  An array of options for the filter.
60      *
61      * @return  void
62      *
63      * @since   11.3
64      */
65     abstract public function execute(array $options = array());
66 }
67