2121abstract 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