Make use of ImageAdapter::checkMemoryLimit()
authorTim Düsterhus <duesterhus@woltlab.com>
Tue, 4 Aug 2020 08:29:28 +0000 (10:29 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Tue, 4 Aug 2020 08:40:22 +0000 (10:40 +0200)
wcfsetup/install/files/lib/system/upload/DefaultUploadFileSaveStrategy.class.php
wcfsetup/install/files/lib/system/upload/UserCoverPhotoUploadFileValidationStrategy.class.php

index 39337985732be866c38d65f49c926991d1f439e3..644a135b9f84799a5b27fe6452278b610a2934db 100644 (file)
@@ -177,15 +177,15 @@ class DefaultUploadFileSaveStrategy implements IUploadFileSaveStrategy {
                                        $object = $parameters['object'];
                                }
                                
+                               $adapter = ImageHandler::getInstance()->getAdapter();
                                // rotate image based on the exif data
                                if (!empty($this->options['rotateImages'])) {
                                        if ($object->isImage) {
-                                               if (FileUtil::checkMemoryLimit($object->width * $object->height * ($object->fileType == 'image/png' ? 4 : 3) * 2.1)) {
+                                               if ($adapter->checkMemoryLimit($object->width, $object->height, $object->fileType)) {
                                                        $exifData = ExifUtil::getExifData($object->getLocation());
                                                        if (!empty($exifData)) {
                                                                $orientation = ExifUtil::getOrientation($exifData);
                                                                if ($orientation != ExifUtil::ORIENTATION_ORIGINAL) {
-                                                                       $adapter = ImageHandler::getInstance()->getAdapter();
                                                                        $adapter->loadFile($object->getLocation());
                                                                        
                                                                        $newImage = null;
@@ -292,12 +292,13 @@ class DefaultUploadFileSaveStrategy implements IUploadFileSaveStrategy {
                        return;
                }
                
+               $adapter = ImageHandler::getInstance()->getAdapter();
+               
                // check memory limit
-               if (!FileUtil::checkMemoryLimit($file->width * $file->height * ($file->fileType == 'image/png' ? 4 : 3) * 2.1)) {
+               if (!$adapter->checkMemoryLimit($file->width, $file->height, $file->fileType)) {
                        return;
                }
                
-               $adapter = ImageHandler::getInstance()->getAdapter();
                $adapter->loadFile($file->getLocation());
                
                $updateData = [];
index dfcaaf0e33d2a75e46075c8b66368b6ffae3bc54..efc03f53877643e0122b346bf3d044a443f8e849 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 namespace wcf\system\upload;
 use wcf\data\user\cover\photo\UserCoverPhoto;
+use wcf\system\image\ImageHandler;
 use wcf\system\WCF;
 use wcf\util\ExifUtil;
-use wcf\util\FileUtil;
 
 /**
  * Upload file validation strategy implementation for user cover photos.
@@ -59,7 +59,7 @@ class UserCoverPhotoUploadFileValidationStrategy implements IUploadFileValidatio
                // estimate if there is enough memory for a resize, if there is,
                // we do not need to mark an image which is too high or too wide
                // as invalid
-               $sufficientMemory = FileUtil::checkMemoryLimit($width * $height * ($uploadFile->getFileExtension() == 'png' ? 4 : 3) * 2.1);
+               $sufficientMemory = ImageHandler::getInstance()->getAdapter()->checkMemoryLimit($width, $height, $imageData['mimeType']);
                
                // check width
                if ($width < UserCoverPhoto::MIN_WIDTH) {