Skip to content

Commit

Permalink
fix thumbnail issue
Browse files Browse the repository at this point in the history
  • Loading branch information
wilso929 authored and wilso929 committed Nov 8, 2023
1 parent 0d2643d commit b6c3330
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Plugin/MediaThumbnail/MediaThumbnailJp2.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}

}

0 comments on commit b6c3330

Please sign in to comment.