1515use OCP \EventDispatcher \IEventDispatcher ;
1616use OCP \EventDispatcher \IEventListener ;
1717use OCP \Files \GenericFileException ;
18- use OCP \Files \NotFoundException ;
1918use OCP \Files \NotPermittedException ;
2019use OCP \FilesMetadata \AMetadataEvent ;
2120use OCP \FilesMetadata \Event \MetadataBackgroundEvent ;
2221use OCP \FilesMetadata \Event \MetadataLiveEvent ;
23- use OCP \IPreview ;
2422use OCP \Lock \LockedException ;
2523
2624/**
@@ -34,11 +32,6 @@ class GenerateBlurhashMetadata implements IEventListener {
3432 private const COMPONENTS_X = 4 ;
3533 private const COMPONENTS_Y = 3 ;
3634
37- public function __construct (
38- private IPreview $ preview ,
39- ) {
40- }
41-
4235 /**
4336 * @throws NotPermittedException
4437 * @throws GenericFileException
@@ -67,23 +60,11 @@ public function handle(Event $event): void {
6760 return ;
6861 }
6962
70- $ image = false ;
71- try {
72- // using preview image to generate the blurhash
73- $ preview = $ this ->preview ->getPreview ($ file , 256 , 256 );
74- $ image = @imagecreatefromstring ($ preview ->getContent ());
75- } catch (NotFoundException $ e ) {
76- // https://github.com/nextcloud/server/blob/9d70fd3e64b60a316a03fb2b237891380c310c58/lib/private/legacy/OC_Image.php#L668
77- // The preview system can fail on huge picture, in that case we use our own image resizer.
78- if (str_starts_with ($ file ->getMimetype (), 'image/ ' )) {
79- $ image = $ this ->resizedImageFromFile ($ file );
80- }
81- }
82-
83- if ($ image === false ) {
63+ if (!str_starts_with ($ file ->getMimetype (), 'image/ ' )) {
8464 return ;
8565 }
8666
67+ $ image = $ this ->resizedImageFromFile ($ file );
8768 $ metadata ->setString ('blurhash ' , $ this ->generateBlurHash ($ image ))
8869 ->setEtag ('blurhash ' , $ currentEtag );
8970 }
0 commit comments