- $width = $image->getWidth();
- $height = $image->getHeight();
-
- $maximagesize = Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize'));
-
- if ($maximagesize && $filesize > $maximagesize) {
- // Scale down to multiples of 640 until the maximum size isn't exceeded anymore
- foreach ([5120, 2560, 1280, 640, 320] as $pixels) {
- if ($filesize > $maximagesize && max($width, $height) > $pixels) {
- DI::logger()->info('Resize', ['size' => $filesize, 'width' => $width, 'height' => $height, 'max' => $maximagesize, 'pixels' => $pixels]);
- $image->scaleDown($pixels);
- $filesize = strlen($image->asString());
- $width = $image->getWidth();
- $height = $image->getHeight();
- }
- }
-
- if ($filesize > $maximagesize) {
- DI::logger()->notice('Image size is too big', ['size' => $filesize, 'max' => $maximagesize]);
- return -1;
- }
- }
-
- $width = $image->getWidth();
- $height = $image->getHeight();
- $smallest = 0;