2016-10-17 15:53:23 -04:00
|
|
|
<?php
|
2025-06-30 09:04:05 -04:00
|
|
|
|
2016-10-17 15:53:23 -04:00
|
|
|
/**
|
2024-05-23 03:26:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2016-10-17 15:53:23 -04:00
|
|
|
*/
|
|
|
|
|
namespace OC\Preview;
|
|
|
|
|
|
|
|
|
|
use OCP\Files\File;
|
|
|
|
|
use OCP\Files\SimpleFS\ISimpleFile;
|
|
|
|
|
use OCP\IImage;
|
2018-01-12 18:34:28 -05:00
|
|
|
use OCP\Image as OCPImage;
|
2025-09-12 07:09:47 -04:00
|
|
|
use OCP\IPreview;
|
2019-06-04 09:25:25 -04:00
|
|
|
use OCP\Preview\IProviderV2;
|
2016-10-17 15:53:23 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Very small wrapper class to make the generator fully unit testable
|
2025-09-12 07:09:47 -04:00
|
|
|
* @psalm-import-type ProviderClosure from IPreview
|
2016-10-17 15:53:23 -04:00
|
|
|
*/
|
|
|
|
|
class GeneratorHelper {
|
2025-09-12 07:09:47 -04:00
|
|
|
public function getThumbnail(IProviderV2 $provider, File $file, int $maxWidth, int $maxHeight, bool $crop = false): IImage|false {
|
2020-11-16 16:16:34 -05:00
|
|
|
if ($provider instanceof Imaginary) {
|
|
|
|
|
return $provider->getCroppedThumbnail($file, $maxWidth, $maxHeight, $crop) ?? false;
|
|
|
|
|
}
|
|
|
|
|
return $provider->getThumbnail($file, $maxWidth, $maxHeight) ?? false;
|
2016-10-17 15:53:23 -04:00
|
|
|
}
|
|
|
|
|
|
2025-08-28 08:25:55 -04:00
|
|
|
public function getImage(ISimpleFile $maxPreview): IImage {
|
2018-01-12 18:34:28 -05:00
|
|
|
$image = new OCPImage();
|
|
|
|
|
$image->loadFromData($maxPreview->getContent());
|
|
|
|
|
return $image;
|
2016-10-17 15:53:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-09-12 07:09:47 -04:00
|
|
|
* @param \Closure|string $providerClosure (string is only authorized in unit tests)
|
2016-10-17 15:53:23 -04:00
|
|
|
*/
|
2025-09-12 07:09:47 -04:00
|
|
|
public function getProvider(\Closure|string $providerClosure): IProviderV2|false {
|
|
|
|
|
return $providerClosure();
|
2016-10-17 15:53:23 -04:00
|
|
|
}
|
|
|
|
|
}
|