|
15 | 15 | use wcf\data\user\UserProfileList; |
16 | 16 | use wcf\system\bbcode\BBCodeHandler; |
17 | 17 | use wcf\system\database\util\PreparedStatementConditionBuilder; |
| 18 | +use wcf\system\exception\SystemException; |
| 19 | +use wcf\system\file\processor\UserAvatarFileProcessor; |
18 | 20 | use wcf\system\html\input\HtmlInputProcessor; |
| 21 | +use wcf\system\image\ImageHandler; |
19 | 22 | use wcf\system\user\storage\UserStorageHandler; |
20 | 23 | use wcf\system\WCF; |
21 | 24 |
|
@@ -230,6 +233,64 @@ public function execute() |
230 | 233 | continue; |
231 | 234 | } |
232 | 235 |
|
| 236 | + $width = $avatar->width; |
| 237 | + $height = $avatar->height; |
| 238 | + if ($width != $height) { |
| 239 | + // make avatar quadratic |
| 240 | + $width = $height = \min($avatar->width, $avatar->height, UserAvatarFileProcessor::AVATAR_SIZE); |
| 241 | + $adapter = ImageHandler::getInstance()->getAdapter(); |
| 242 | + |
| 243 | + try { |
| 244 | + $adapter->loadFile($avatar->getLocation()); |
| 245 | + } catch (SystemException $e) { |
| 246 | + // broken image |
| 247 | + $editor->delete(); |
| 248 | + continue; |
| 249 | + } |
| 250 | + |
| 251 | + $thumbnail = $adapter->createThumbnail($width, $height, false); |
| 252 | + $adapter->writeImage($thumbnail, $avatar->getLocation()); |
| 253 | + // Clear thumbnail as soon as possible to free up the memory. |
| 254 | + $thumbnail = null; |
| 255 | + } |
| 256 | + |
| 257 | + if ( |
| 258 | + $width != UserAvatarFileProcessor::AVATAR_SIZE |
| 259 | + && $width != UserAvatarFileProcessor::AVATAR_SIZE_2X |
| 260 | + ) { |
| 261 | + // resize avatar |
| 262 | + $adapter = ImageHandler::getInstance()->getAdapter(); |
| 263 | + |
| 264 | + try { |
| 265 | + $adapter->loadFile($avatar->getLocation()); |
| 266 | + } catch (SystemException $e) { |
| 267 | + // broken image |
| 268 | + $editor->delete(); |
| 269 | + continue; |
| 270 | + } |
| 271 | + |
| 272 | + if ($width > UserAvatarFileProcessor::AVATAR_SIZE_2X) { |
| 273 | + $adapter->resize( |
| 274 | + 0, |
| 275 | + 0, |
| 276 | + $width, |
| 277 | + $height, |
| 278 | + UserAvatarFileProcessor::AVATAR_SIZE_2X, |
| 279 | + UserAvatarFileProcessor::AVATAR_SIZE_2X |
| 280 | + ); |
| 281 | + } else { |
| 282 | + $adapter->resize( |
| 283 | + 0, |
| 284 | + 0, |
| 285 | + $width, |
| 286 | + $height, |
| 287 | + UserAvatarFileProcessor::AVATAR_SIZE, |
| 288 | + UserAvatarFileProcessor::AVATAR_SIZE |
| 289 | + ); |
| 290 | + } |
| 291 | + $adapter->writeImage($adapter->getImage(), $avatar->getLocation()); |
| 292 | + } |
| 293 | + |
233 | 294 | $file = FileEditor::createFromExistingFile( |
234 | 295 | $avatar->getLocation(), |
235 | 296 | $avatar->avatarName, |
|
0 commit comments