Skip to content

Commit 00e843b

Browse files
committed
Modernisation - Make ImageFilter aware of GdImage
1 parent bf6b89b commit 00e843b

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/ImageFilter.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
abstract class ImageFilter implements LoggerAwareInterface
2222
{
2323
/**
24-
* @var resource The image resource handle.
24+
* @var resource|\GdImage The image resource handle.
2525
* @since 1.0
2626
*/
2727
protected $handle;
@@ -35,7 +35,7 @@ abstract class ImageFilter implements LoggerAwareInterface
3535
/**
3636
* Class constructor.
3737
*
38-
* @param resource $handle The image resource on which to apply the filter.
38+
* @param resource|\GdImage $handle The image resource on which to apply the filter.
3939
*
4040
* @since 1.0
4141
* @throws \InvalidArgumentException
@@ -55,7 +55,7 @@ public function __construct($handle)
5555
}
5656

5757
// Make sure the file handle is valid.
58-
if (!\is_resource($handle) || (get_resource_type($handle) != 'gd'))
58+
if (!$this->isValidImage($handle))
5959
{
6060
$this->getLogger()->error('The image handle is invalid for the image filter.');
6161

@@ -88,7 +88,7 @@ public function getLogger()
8888
*
8989
* @param LoggerInterface $logger A PSR-3 compliant logger.
9090
*
91-
* @return Image This object for message chaining.
91+
* @return ImageFilter This object for message chaining.
9292
*
9393
* @since 1.0
9494
*/
@@ -109,4 +109,16 @@ public function setLogger(LoggerInterface $logger)
109109
* @since 1.0
110110
*/
111111
abstract public function execute(array $options = array());
112+
113+
/**
114+
* @param mixed $handle A potential image handle
115+
*
116+
* @return boolean
117+
*/
118+
private function isValidImage($handle)
119+
{
120+
// @todo Remove resource check, once PHP7 support is dropped.
121+
return (\is_resource($handle) && \get_resource_type($handle) === 'gd')
122+
|| (\is_object($handle) && $handle instanceof \GDImage);
123+
}
112124
}

0 commit comments

Comments
 (0)