Skip to content

Commit

Permalink
fix: don't persist previews used during blurhash generation
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
  • Loading branch information
st3iny committed Jul 30, 2024
1 parent c882d78 commit 644f795
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions lib/private/Blurhash/Listener/GenerateBlurhashMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,11 @@ public function handle(Event $event): void {
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 image resizer.
if (str_starts_with($file->getMimetype(), 'image/')) {
$image = $this->resizedImageFromFile($file);
}
}

if ($image === false) {
if (!str_starts_with($file->getMimetype(), 'image/')) {
return;
}

$image = $this->resizedImageFromFile($file);
$metadata->setString('blurhash', $this->generateBlurHash($image))
->setEtag('blurhash', $currentEtag);
}
Expand Down

0 comments on commit 644f795

Please sign in to comment.