Support for WebP images (#3861)
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / image / adapter / GDImageAdapter.class.php
index 5ffad1643824055f0135486255984268f62ccf5b..9d61e08f67ac7047db35861509ea6eb8331742f5 100644 (file)
@@ -111,9 +111,16 @@ class GDImageAdapter implements IImageAdapter {
                                }
                        break;
                        
+                       case IMAGETYPE_WEBP:
+                               // suppress warnings and properly handle errors
+                               $this->image = @imagecreatefromwebp($file);
+                               if ($this->image === false) {
+                                       throw new SystemException("Could not read webp image '".$file."'.");
+                               }
+                       break;
+                       
                        default:
                                throw new SystemException("Could not read image '".$file."', format is not recognized.");
-                       break;
                }
        }
        
@@ -348,6 +355,9 @@ class GDImageAdapter implements IImageAdapter {
                else if ($this->type == IMAGETYPE_PNG) {
                        imagepng($image);
                }
+               else if ($this->type == IMAGETYPE_WEBP) {
+                       imagewebp($image);
+               }
                else if (function_exists('imageJPEG')) {
                        imagejpeg($image, null, 90);
                }