Back to ImageFilter class

Method __construct

public
__construct
(mixed $handle)
Class constructor.
Parameters
  • resource $handle The image resource on which to apply the filter.
Since
  • 1.7.3
-
  • \InvalidArgumentException
  • \RuntimeException
Class: ImageFilter
Project: Joomla

Method __construct - Source code

/**
 * Class constructor.
 *
 * @param   resource  $handle  The image resource on which to apply the filter.
 *
 * @since   1.7.3
 * @throws  \InvalidArgumentException
 * @throws  \RuntimeException
 */
public function __construct($handle)
{
    // Verify that image filter support for PHP is available.
    if (!\function_exists('imagefilter')) {
        throw new \RuntimeException('The imagefilter function for PHP is not available.');
    }
    /**
     * Make sure the file handle is valid.
     * @todo: Remove check for resource when we only support PHP 8
     */
    if (!(\is_object($handle) && get_class($handle) == 'GdImage' || \is_resource($handle) && get_resource_type($handle) == 'gd')) {
        throw new \InvalidArgumentException('The image handle is invalid for the image filter.');
    }
    $this->handle = $handle;
}