Beispiel #1
0
 /**
  * Constructs a new ImageNotFoundResponse
  * @param int   $maxWidth
  * @param int   $maxHeight
  * @param int   $code
  * @param string $message
  */
 public function __construct($maxWidth, $maxHeight, $code, $message)
 {
     if ($maxWidth == 0) {
         $maxWidth = 300;
     }
     if ($maxHeight == 0) {
         $maxHeight = 300;
     }
     $imagine = new Imagine();
     $size = new Box(300, 300);
     $image = $imagine->create($size);
     $black = $image->palette()->color("000");
     $path = realpath(__DIR__ . "/../Resources/public/fonts/OpenSans-Regular.ttf");
     $font = $imagine->font($path, 24, $black);
     $image->draw()->text($message, $font, new Point(0, 0));
     $box = $image->getSize();
     $box = $box->widen($maxWidth);
     if ($box->getHeight() > $maxHeight) {
         $box = $box->heighten($maxHeight);
     }
     $image->resize($box);
     return parent::__construct($image->get("png"), $code, array("Content-Type" => "image/png"));
 }
Beispiel #2
0
 /**
  * @param int    $fontSize
  * @param string $textColor
  * @param string $fontName
  * @return \Imagine\Gd\Font|\Imagine\Image\FontInterface
  */
 protected function font($fontSize = null, $textColor = null, $fontName = null)
 {
     return $this->imagine->font($fontName ? $fontName : $this->fontName, $fontSize ? $fontSize : $this->fontSize, $textColor ? is_object($textColor) ? $textColor : $this->color($textColor) : $this->color($this->textColor));
 }