From b6c3330c5395343021be773817b7ccc4b71e7cde Mon Sep 17 00:00:00 2001 From: wilso929 Date: Wed, 8 Nov 2023 10:01:22 -0500 Subject: [PATCH] fix thumbnail issue --- src/Plugin/MediaThumbnail/MediaThumbnailJp2.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Plugin/MediaThumbnail/MediaThumbnailJp2.php b/src/Plugin/MediaThumbnail/MediaThumbnailJp2.php index 5677a37..c16efdc 100644 --- a/src/Plugin/MediaThumbnail/MediaThumbnailJp2.php +++ b/src/Plugin/MediaThumbnail/MediaThumbnailJp2.php @@ -46,16 +46,24 @@ public function createThumbnail($sourceUri) { $this->logger->warning($e->getMessage()); return NULL; } - + $format = ".jpg"; $im = new \Imagick(); - $im->readimage("/tmp/" . $filename . ".jpg"); + try{ + $im->readimage("/tmp/" . $filename . $format); + }catch (\ImagickException $e){ + $sourceUri = \Drupal::config('media.settings')->get('icon_base_uri') . '/' . 'generic.png'; + $path = $this->fileSystem->realpath($sourceUri); + $im->readimage($path); + $format = ".png"; + } $image = $im->getImageBlob(); $im->clear(); $im->destroy(); // Return a new managed file object using the generated thumbnail. - return \Drupal::service('file.repository')->writeData($image, $sourceUri . '.jpg'); + return \Drupal::service('file.repository')->writeData($image, $sourceUri . $format); } } +