public function PhotosImage::derivative in Album Photos 8.5
Same name and namespace in other branches
- 8.4 src/PhotosImage.php \Drupal\photos\PhotosImage::derivative()
Generate image style derivatives and return image file URL.
Originally added to create private image style derivatives.
Parameters
string $uri: File URI.
string $style_name: Image style name.
string $scheme: File system scheme.
Return value
string The image URL.
File
- src/
PhotosImage.php, line 140
Class
- PhotosImage
- Create images object.
Namespace
Drupal\photosCode
public function derivative($uri, $style_name, $scheme = 'private') {
// @todo adapt this to work with all file system scheme options.
// 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.
return file_create_url($destination);
}