function GDToolkit::setResource

Same name and namespace in other branches
  1. 8.9.x core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php \Drupal\system\Plugin\ImageToolkit\GDToolkit::setResource()
  2. 10 core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php \Drupal\system\Plugin\ImageToolkit\GDToolkit::setResource()

Sets the GD image resource.

Parameters

resource|\GdImage $resource: The GD image resource.

Return value

$this An instance of the current toolkit object.

1 call to GDToolkit::setResource()
GDToolkit::load in core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php
Loads a GD resource from a file.

File

core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php, line 137

Class

GDToolkit
Defines the GD2 toolkit for image manipulation within Drupal.

Namespace

Drupal\system\Plugin\ImageToolkit

Code

public function setResource($resource) {
    if (!(is_object($resource) && $resource instanceof \GdImage)) {
        // Since PHP 8.0 resource should be \GdImage, for previous versions it
        // should be resource.
        // @TODO clean-up for PHP 8.0+ https://www.drupal.org/node/3173031
        if (!is_resource($resource) || get_resource_type($resource) != 'gd') {
            throw new \InvalidArgumentException('Invalid resource argument');
        }
    }
    $this->preLoadInfo = NULL;
    $this->resource = $resource;
    return $this;
}

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