diff --git a/kcfinder/lib/class_gd.php b/kcfinder/lib/class_gd.php
index adfc89784d4af89c457c5986b6f2d51edbe35233..0ac2aaea996434370ce1822fba0a33df657830b5 100644
--- a/kcfinder/lib/class_gd.php
+++ b/kcfinder/lib/class_gd.php
@@ -52,8 +52,13 @@ class gd {
             $height = @imagesy($image);
 
         } elseif (is_array($image)) {
-            list($key, $width) = each($image);
-            list($key, $height) = each($image);
+            $key = key($image);
+            $width = current($image);
+            next($image);
+
+            $key = key($image);
+            $height = current($image);
+            next($image);
             $image = imagecreatetruecolor($width, $height);
 
         } elseif (false !== (list($width, $height, $type) = @getimagesize($image))) {
@@ -71,8 +76,8 @@ class gd {
         }
 
         $return = (
-            is_resource($image) &&
-            (get_resource_type($image) == "gd") &&
+            ((is_resource($image) && get_resource_type($image) === 'gd') ||
+            (is_object($image) && $image instanceof \GDImage)) &&
             isset($width) &&
             isset($height) &&
             (preg_match('/^[1-9][0-9]*$/', $width) !== false) &&