code: public function calculateWidth($text, $size = self::TEXT_SIZE)
      {
          $size = $this->convertToPt($size);
          $box  = imagettfbbox($size, 0, $this->fontPath, $text);
  
          return round(abs($box[2] - $box[0]) + self::SHIELD_PADDING_EXTERNAL + self::SHIELD_PADDING_INTERNAL, 1);
      }
docs: Calculate the width of the text box.
  
  @param string $text
  @param int    $size
  
  @return float