Skip to content
Snippets Groups Projects

Issue #3437294: Fatal error if image file missing

1 file
+ 19
11
Compare changes
  • Side-by-side
  • Inline
@@ -244,18 +244,26 @@ class ImageBase64Formatter extends ImageFormatter {
}
// Encode image in base64 format.
$image_file = file_get_contents($absolute_path);
$base_64_image = base64_encode($image_file);
$base_64_data = "data:$image_type;base64,$base_64_image";
// Get the image's width and height, int|null.
$image_media = $this->imageFactory->get($absolute_path);
if ($image_media->isValid()) {
$width = $image_media->getWidth();
$height = $image_media->getHeight();
}
else {
if (empty($absolute_path) || !file_exists($absolute_path)) {
\Drupal::logger('image_base64_formatter')->error('Image file not found at: @uri', ['@uri' => $absolute_path]);
$base_64_data = NULL;
$width = $height = NULL;
} else {
// Encode image in base64 format.
$image_file = file_get_contents($absolute_path);
$base_64_image = base64_encode($image_file);
$base_64_data = "data:$image_type;base64,$base_64_image";
// Get the image's width and height, int|null.
$image_media = $this->imageFactory->get($absolute_path);
if ($image_media->isValid()) {
$width = $image_media->getWidth();
$height = $image_media->getHeight();
} else {
$width = $height = NULL;
}
}
switch ($image_display) {
Loading