private static function calculateSourceBox(array $srcSize = [], float $srcRatio = 1, array $dstSize = [],
                                               float $dstRatio = 1): array
    {
        $srcBox = ['x' => 0, 'y' => 0, 'w' => $srcSize['w'], 'h' => $srcSize['h']];
        if ($srcRatio != $dstRatio) {
            $srcBox['w'] = $dstSize['w'];
            $srcBox['h'] = $dstSize['h'];

            while ($srcBox['w'] < $srcSize['w'] && $srcBox['h'] < $srcSize['h']) {
                $srcBox['w'] *= 10;
                $srcBox['h'] *= 10;
            }

            if ($srcBox['w'] > $srcSize['w']) {
                $srcBox['w'] = $srcSize['w'];
                $srcBox['h'] = (int)\floor($srcSize['w'] / $dstRatio);
            }
            if ($srcBox['h'] > $srcSize['h']) {
                $srcBox['h'] = $srcSize['h'];
                $srcBox['w'] = (int)\floor($srcSize['h'] * $dstRatio);
            }

            $srcBox['x'] = 0;
            $srcBox['y'] = (int)\floor(($srcSize['h'] - $srcBox['h']) / 2);

            if ($srcBox['w'] < $srcSize['w']) {
                $srcBox['x'] = (int)\floor(($srcSize['w'] - $srcBox['w']) / 2);
                $srcBox['y'] = 0;
            }
        }
        return $srcBox;
    }