public static function getCropSize($originalSize, $transform, $allowUpscale): Box
    {
        $width = $originalSize->getWidth();
        $height = $originalSize->getHeight();
        $aspect = $width / $height;

        if (isset($transform['width'], $transform['height'])) {
            $width = (int)$transform['width'];
            $height = (int)$transform['height'];
        } else {
            if (isset($transform['width'])) {
                $width = (int)$transform['width'];
                $height = (int)floor((int)$transform['width'] / $aspect);
            } else {
                if (isset($transform['height'])) {
                    $width = (int)floor((int)$transform['height'] * $aspect);
                    $height = (int)$transform['height'];
                }
            }
        }

        // check if we want to upscale. If not, adjust the transform here 
        if (!$allowUpscale) {
            list($width, $height) = self::enforceMaxSize($width, $height, $originalSize, true);
        }

        // ensure that size is larger than 0
        if ($width <= 0) {
            $width = 1;
        }
        if ($height <= 0) {
            $height = 1;
        }

        return new Box((int)$width, (int)$height);
    }