protected function drawCenteredText($text, $color)
    {
        $width = $this->image->getSize()->getWidth();
        $height = $this->image->getSize()->getHeight();
        $fontColor = $this->image->palette()->color('#' . $color);
        $fontSize = 48;
        $widthFactor = $width > 160 ? 0.8 : 0.9;
        $heightFactor = $height > 160 ? 0.8 : 0.9;
        do {
            $font = $this->getImagineService()
              ->font(__DIR__ . '/../../../data/font/Roboto-Regular.ttf', $fontSize, $fontColor);
            $fontBox = $font->box($text);
            $fontSize = round($fontSize * 0.8);
            
        } while ($fontSize > 5
          && ($width * $widthFactor < $fontBox->getWidth() || $height * $heightFactor < $fontBox->getHeight()));

        $pointX = max(0, floor(($width - $fontBox->getWidth()) / 2));
        $pointY = max(0, floor(($height - $fontBox->getHeight()) / 2));
        
        $this->image->draw()->text($text, $font, new Point($pointX, $pointY));
    }