nextcloud/lib/private/Preview/GeneratorHelper.php
Carl Schwan cb82a9ef04 refactor(preview): Cleanup a bit the public interface
* Remove old IProvider interface, it's been deprecated since 17.0.0 (8
  years)
* Add type hinting to the IPreview interface and mark it as consumeable
  only
* Remove unused arguments from GeneratorHelper

Signed-off-by: Carl Schwan <carl.schwan@nextcloud.com>
2025-10-09 17:41:13 +02:00

40 lines
1.1 KiB
PHP

<?php
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OC\Preview;
use OCP\Files\File;
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\IImage;
use OCP\Image as OCPImage;
use OCP\IPreview;
use OCP\Preview\IProviderV2;
/**
* Very small wrapper class to make the generator fully unit testable
* @psalm-import-type ProviderClosure from IPreview
*/
class GeneratorHelper {
public function getThumbnail(IProviderV2 $provider, File $file, int $maxWidth, int $maxHeight, bool $crop = false): IImage|false {
if ($provider instanceof Imaginary) {
return $provider->getCroppedThumbnail($file, $maxWidth, $maxHeight, $crop) ?? false;
}
return $provider->getThumbnail($file, $maxWidth, $maxHeight) ?? false;
}
public function getImage(ISimpleFile $maxPreview): IImage {
$image = new OCPImage();
$image->loadFromData($maxPreview->getContent());
return $image;
}
/**
* @param \Closure|string $providerClosure (string is only authorized in unit tests)
*/
public function getProvider(\Closure|string $providerClosure): IProviderV2|false {
return $providerClosure();
}
}