Merge branch '5.2' into 5.3
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / image / adapter / GDImageAdapter.class.php
index 00c53ef87117869c5bcdf0ca8cd88cd2dc022e35..5ffad1643824055f0135486255984268f62ccf5b 100644 (file)
@@ -56,11 +56,20 @@ class GDImageAdapter implements IImageAdapter {
                @ini_set('gd.jpeg_ignore_warning', '1');
        }
        
+       /**
+        * Returns whether the given image is a valid GD resource / GD object
+        * 
+        * @return      boolean
+        */
+       public function isImage($image) {
+               return (is_resource($image) && get_resource_type($image) === 'gd') || (is_object($image) && $image instanceof \GdImage);
+       }
+       
        /**
         * @inheritDoc
         */
        public function load($image, $type = '') {
-               if (!is_resource($image)) {
+               if (!$this->isImage($image)) {
                        throw new SystemException("Image resource is invalid.");
                }
                
@@ -325,7 +334,7 @@ class GDImageAdapter implements IImageAdapter {
         * @inheritDoc
         */
        public function writeImage($image, $filename) {
-               if (!is_resource($image)) {
+               if (!$this->isImage($image)) {
                        throw new SystemException("Given image is not a valid image resource.");
                }
                
@@ -420,7 +429,7 @@ class GDImageAdapter implements IImageAdapter {
         * @param       integer         $pct            opacity percent
         * @return      boolean
         */
-       private function imagecopymerge_alpha($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct) {
+       private function imagecopymerge_alpha($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct) { // phpcs:ignore
                if (!isset($pct)) {
                        return false;
                }