public function getImageSizeInBox(array $imageSize, array $boxSize)
    {
        list($imageWidth, $imageHeight) = $imageSize;
        list($boxWidth, $boxHeight) = $boxSize;

        if (($imageWidth <= $boxWidth) && ($imageHeight <= $boxHeight)) {
            return $imageSize;
        }

        $resizeRatio = min($boxWidth / $imageWidth, $boxHeight / $imageHeight);

        $imageWidth = ceil($imageWidth * $resizeRatio);

        if ($imageWidth > $boxWidth) {
            $imageWidth = $boxWidth;
        }

        $imageHeight = ceil($imageHeight * $resizeRatio);

        if ($imageHeight > $boxHeight) {
            $imageHeight = $boxHeight;
        }

        return array($imageWidth, $imageHeight);
    }