Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
  • Loading branch information
ArtificialOwl committed Jan 4, 2024
1 parent 15688f6 commit 0ca5f48
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions lib/private/Blurhash/Listener/GenerateBlurhashMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class GenerateBlurhashMetadata implements IEventListener {
private const COMPONENTS_Y = 3;

public function __construct(
private IPreview $preview
private IPreview $preview,
) {
}

Expand All @@ -72,19 +72,20 @@ public function handle(Event $event): void {
return;
}

// too heavy to run on the live thread, request a rerun as a background job
if ($event instanceof MetadataLiveEvent) {
$event->requestBackgroundJob();

return;
}

$image = false;
try {
// using preview image to generate the blurhash
$preview = $this->preview->getPreview($file, 256, 256);
$image = imagecreatefromstring($preview->getContent());
} catch (NotFoundException $e) {
// https://github.com/nextcloud/server/blob/9d70fd3e64b60a316a03fb2b237891380c310c58/lib/private/legacy/OC_Image.php#L668
// The preview system can fail on huge picture, in that case we use our own resize image.
// The preview system can fail on huge picture, in that case we use our own image resizer.
if (str_starts_with($file->getMimetype(), 'image/')) {
$image = $this->resizedImageFromFile($file);
}
Expand Down Expand Up @@ -124,11 +125,7 @@ private function resizedImageFromFile(File $file): GdImage|false {
}

$newImage = imagescale($image, $newX, $newY);
if (false !== $newImage) {
$image = $newImage;
}

return $image;
return ($newImage !== false) ? $newImage : $image;
}

/**
Expand Down

0 comments on commit 0ca5f48

Please sign in to comment.