public function getBoxSize(array $imageSize, array $size)
    {
        list($width, $height) = $size;

        if ((null == $width) && (null == $height)) {
            return $imageSize;
        }

        list($imageWidth, $imageHeight) = $imageSize;

        if ((null !== $width) && (null == $height)) {
            $height = ceil($width * ($imageHeight / $imageWidth));

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

            return array($width, $height);
        }

        if ((null === $width) && (null != $height)) {
            $width = ceil($height * ($imageWidth / $imageHeight));

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

            return array($width, $height);
        }

        return $size;
    }