1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- namespace OC\Preview;
- use OC\Archive\ZIP;
- use OCP\Files\File;
- use OCP\IImage;
- abstract class Bundled extends ProviderV2 {
- protected function extractThumbnail(File $file, string $path): ?IImage {
- if ($file->getSize() === 0) {
- return null;
- }
- $sourceTmp = \OC::$server->getTempManager()->getTemporaryFile();
- $targetTmp = \OC::$server->getTempManager()->getTemporaryFile();
- $this->tmpFiles[] = $sourceTmp;
- $this->tmpFiles[] = $targetTmp;
- try {
- $content = $file->fopen('r');
- file_put_contents($sourceTmp, $content);
- $zip = new ZIP($sourceTmp);
- $zip->extractFile($path, $targetTmp);
- $image = new \OCP\Image();
- $image->loadFromFile($targetTmp);
- $image->fixOrientation();
- return $image;
- } catch (\Throwable $e) {
- return null;
- }
- }
- }
|