Skip to content

Commit

Permalink
testing with internal preview system
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 Oct 24, 2023
1 parent 98c679e commit 915577d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/private/Blurhash/Listener/GenerateBlurhashMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@
use OCP\EventDispatcher\IEventListener;
use OCP\FilesMetadata\Event\MetadataBackgroundEvent;
use OCP\FilesMetadata\Event\MetadataLiveEvent;
use OCP\IPreview;

class GenerateBlurhashMetadata implements IEventListener {
private const RESIZE_BOXSIZE = 300;

private const COMPONENTS_X = 4;
private const COMPONENTS_Y = 3;

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

public function handle(Event $event): void {
Expand All @@ -39,7 +42,14 @@ public function handle(Event $event): void {
return;
}

// use our own resize
$image = $this->resizedImageFromFile($file);

// or use the one from the preview system (not working on >4M jpeg photo)
// https://github.com/nextcloud/server/blob/9d70fd3e64b60a316a03fb2b237891380c310c58/lib/private/legacy/OC_Image.php#L668
// $f = $this->preview->getPreview($file, 256, 256);
// $image = imagecreatefromstring($f->getContent());

$metadata = $event->getMetadata();
$metadata->set('blurhash', $this->generateBlurHash($image));
}
Expand Down

0 comments on commit 915577d

Please sign in to comment.