createBlank() public static method

Create a blank image.
public static createBlank ( integer $width = 1, integer $height = 1 ) : Image
$width integer Width in pixels.
$height integer Height in pixels.
return Image
Esempio n. 1
0
 /**
  * Resize helper function.
  *
  * @param Image $image
  * @param int $newWidth
  * @param int $newHeight
  * @param int $targetX
  * @param int $targetY
  * @param int $srcX
  * @param int $srcY
  *
  */
 private function _resize(&$image, $newWidth, $newHeight, $targetX = 0, $targetY = 0, $srcX = 0, $srcY = 0)
 {
     //        $this->_imageCheck();
     if ($image->isAnimated()) {
         // Animated GIF
         $gift = new GifHelper();
         $blocks = $gift->resize($image->getBlocks(), $newWidth, $newHeight);
         // Resize image instance
         $image = new Image($image->getCore(), $image->getImageFile(), $newWidth, $newHeight, $image->getType(), $blocks, true);
     } else {
         // Create blank image
         $newImage = Image::createBlank($newWidth, $newHeight);
         if (ImageType::PNG === $image->getType()) {
             // Preserve PNG transparency
             $newImage->fullAlphaMode(true);
         }
         imagecopyresampled($newImage->getCore(), $image->getCore(), $targetX, $targetY, $srcX, $srcY, $newWidth, $newHeight, $image->getWidth(), $image->getHeight());
         // Free memory of old resource
         imagedestroy($image->getCore());
         // Resize image instance
         $image = new Image($newImage->getCore(), $image->getImageFile(), $newWidth, $newHeight, $image->getType());
     }
 }
Esempio n. 2
0
 /**
  * Create a blank image.
  *
  * @param int $width Width of image in pixels.
  * @param int $height Height of image in pixels.
  *
  * @return ImageInterface
  * @throws \Exception
  */
 public static function createBlankImage($width = 1, $height = 1)
 {
     $editorName = self::detectAvailableEditor();
     if ('Imagick' === $editorName) {
         return ImagickImage::createBlank($width, $height);
     } else {
         return GdImage::createBlank($width, $height);
     }
 }