function Image::__construct

Same name in this branch
  1. 11.x core/modules/media/src/Plugin/media/Source/Image.php \Drupal\media\Plugin\media\Source\Image::__construct()
Same name and namespace in other branches
  1. 9 core/modules/media/src/Plugin/media/Source/Image.php \Drupal\media\Plugin\media\Source\Image::__construct()
  2. 9 core/modules/image/src/Plugin/InPlaceEditor/Image.php \Drupal\image\Plugin\InPlaceEditor\Image::__construct()
  3. 9 core/lib/Drupal/Core/Image/Image.php \Drupal\Core\Image\Image::__construct()
  4. 8.9.x core/modules/media/src/Plugin/media/Source/Image.php \Drupal\media\Plugin\media\Source\Image::__construct()
  5. 8.9.x core/lib/Drupal/Core/Image/Image.php \Drupal\Core\Image\Image::__construct()
  6. 10 core/modules/media/src/Plugin/media/Source/Image.php \Drupal\media\Plugin\media\Source\Image::__construct()
  7. 10 core/lib/Drupal/Core/Image/Image.php \Drupal\Core\Image\Image::__construct()

Constructs a new Image object.

Parameters

\Drupal\Core\ImageToolkit\ImageToolkitInterface $toolkit: The image toolkit.

string|null $source: (optional) The path to an image file, or NULL to construct the object with no image source.

File

core/lib/Drupal/Core/Image/Image.php, line 47

Class

Image
Defines an image object to represent an image file.

Namespace

Drupal\Core\Image

Code

public function __construct(ImageToolkitInterface $toolkit, $source = NULL) {
    $this->toolkit = $toolkit;
    if ($source) {
        $this->source = $source;
        $this->getToolkit()
            ->setSource($this->source);
        // Defer image file validity check to the toolkit.
        if ($this->getToolkit()
            ->parseFile()) {
            $this->fileSize = filesize($this->source);
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.