Optimized avatar upload
authorMarcel Werk <burntime@woltlab.com>
Tue, 28 May 2013 22:40:04 +0000 (00:40 +0200)
committerMarcel Werk <burntime@woltlab.com>
Tue, 28 May 2013 22:40:04 +0000 (00:40 +0200)
wcfsetup/install/files/lib/data/user/avatar/UserAvatarAction.class.php

index 3d6404cb7cb0bc33afa91195570f02b65140cfc4..16927efdf6fe4d81be33e61fbc8ee0581f93975e 100644 (file)
@@ -258,10 +258,18 @@ class UserAvatarAction extends AbstractDatabaseObjectAction {
                $imageData = getimagesize($filename);
                if ($imageData[0] > MAX_AVATAR_WIDTH || $imageData[1] > MAX_AVATAR_HEIGHT) {
                        try {
+                               $obtainDimensions = true;
+                               if (MAX_AVATAR_WIDTH / $imageData[0] < MAX_AVATAR_HEIGHT / $imageData[1]) {
+                                       if (round($imageData[1] * (MAX_AVATAR_WIDTH / $imageData[0])) < 48) $obtainDimensions = false;
+                               }
+                               else {
+                                       if (round($imageData[0] * (MAX_AVATAR_HEIGHT / $imageData[1])) < 48) $obtainDimensions = false;
+                               }
+                               
                                $adapter = ImageHandler::getInstance()->getAdapter();
                                $adapter->loadFile($filename);
                                $filename = FileUtil::getTemporaryFilename();
-                               $thumbnail = $adapter->createThumbnail(MAX_AVATAR_WIDTH, MAX_AVATAR_HEIGHT, false);
+                               $thumbnail = $adapter->createThumbnail(MAX_AVATAR_WIDTH, MAX_AVATAR_HEIGHT, $obtainDimensions);
                                $adapter->writeImage($thumbnail, $filename);
                        }
                        catch (SystemException $e) {