You are here

public function PhotosImage::derivative in Album Photos 8.4

Same name and namespace in other branches
  1. 8.5 src/PhotosImage.php \Drupal\photos\PhotosImage::derivative()

Generate image style derivatives and return image file URL.

Originally added to create private image style derivatives.

File

src/PhotosImage.php, line 126

Class

PhotosImage
Create images object.

Namespace

Drupal\photos

Code

public function derivative($uri, $style_name, $scheme = 'private') {

  // Load the image style configuration entity.
  $style = ImageStyle::load($style_name);

  // Create URI with fid_{fid}.
  $pathinfo = pathinfo($uri);
  $ext = strtolower($pathinfo['extension']);

  // Set temporary file destination.
  $destination = $scheme . '://photos/tmp_images/' . $style_name . '/image_' . $this->fid . '.' . $ext;

  // Create image file.
  $style
    ->createDerivative($uri, $destination);

  // Return URL.
  $url = file_create_url($destination);
  return $url;
}