public function PhotosImageFile::derivative in Album Photos 6.0.x
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/
PhotosImageFile.php, line 140
Class
- PhotosImageFile
- 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);
}