You are here

public function ImageStyleWithPipeline::createDerivative in Image Optimize (or ImageAPI Optimize) 4.x

Same name and namespace in other branches
  1. 8.3 src/Entity/ImageStyleWithPipeline.php \Drupal\imageapi_optimize\Entity\ImageStyleWithPipeline::createDerivative()
  2. 8.2 src/Entity/ImageStyleWithPipeline.php \Drupal\imageapi_optimize\Entity\ImageStyleWithPipeline::createDerivative()

Creates a new image derivative based on this image style.

Generates an image derivative applying all image effects and saving the resulting image.

Parameters

string $original_uri: Original image file URI.

string $derivative_uri: Derivative image file URI.

Return value

bool TRUE if an image derivative was generated, or FALSE if the image derivative could not be generated.

Overrides ImageStyle::createDerivative

File

src/Entity/ImageStyleWithPipeline.php, line 20

Class

ImageStyleWithPipeline

Namespace

Drupal\imageapi_optimize\Entity

Code

public function createDerivative($original_uri, $derivative_uri) {
  $result = parent::createDerivative($original_uri, $derivative_uri);
  if ($result) {

    // Apply the pipeline to the $derivative_uri.
    if ($this
      ->hasPipeline()) {
      $this
        ->getPipelineEntity()
        ->applyToImage($derivative_uri);
    }
  }

  // Always return the result of the parent class processing.
  return $result;
}