Skip to content

Commit

Permalink
add fallbackimage style null check
Browse files Browse the repository at this point in the history
  • Loading branch information
woldtwerk committed Mar 1, 2021
1 parent 4f37ff2 commit 8f3ab24
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions woldtwerk_image.module
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,22 @@ function woldtwerk_image_preprocess_responsive_image(&$variables) {

$fallback_image_style = ImageStyle::load($responsive_image_style
->getFallbackImageStyle());
$fallback_image_uri = $fallback_image_style->buildUri($variables['uri']);
$image = \Drupal::service('image.factory')->get($variables['uri']);
$image_type = $image->getMimeType();

/* Create Image Style File if it doesn't exist */
if (!file_exists($fallback_image_uri)) {
$fallback_image_style->createDerivative($image->getSource(), $fallback_image_uri);
}
if ($fallback_image_style) {
$fallback_image_uri = $fallback_image_style->buildUri($variables['uri']);
$image_type = $image->getMimeType();

/* Create Image Style File if it doesn't exist */
if (!file_exists($fallback_image_uri)) {
$fallback_image_style->createDerivative($image->getSource(), $fallback_image_uri);
}

/* Check if createDerivative worked */
if (file_exists($fallback_image_uri)) {
$image_file = file_get_contents($fallback_image_uri);
$base_64_image = base64_encode($image_file);
$variables['base_64_data'] = "data:$image_type;base64,$base_64_image";
/* Check if createDerivative worked */
if (file_exists($fallback_image_uri)) {
$image_file = file_get_contents($fallback_image_uri);
$base_64_image = base64_encode($image_file);
$variables['base_64_data'] = "data:$image_type;base64,$base_64_image";
}
}
}

0 comments on commit 8f3ab24

Please sign in to comment.