diff --git a/lib/Classifiers/Classifier.php b/lib/Classifiers/Classifier.php index a197bc75..be27a7cd 100644 --- a/lib/Classifiers/Classifier.php +++ b/lib/Classifiers/Classifier.php @@ -272,20 +272,25 @@ private function getConvertedFilePath(Node $file): string { return $path; } - try { - $this->logger->debug('generating preview of ' . $file->getId() . ' with dimension '.self::TEMP_FILE_DIMENSION); + if ($this->previewProvider->isAvailable($file)) { + try { + $this->logger->debug('generating preview of ' . $file->getId() . ' with dimension ' . self::TEMP_FILE_DIMENSION . ' using nextcloud preview manager'); + return $this->generatePreviewWithProvider($file); + } catch (\Throwable $e) { + $this->logger->warning('Failed to generate preview of ' . $file->getId() . ' with dimension ' . self::TEMP_FILE_DIMENSION . ' with nextcloud preview manager: ' . $e->getMessage()); + } + } - $imageType = exif_imagetype($path); //To troubleshoot console errors, GD does not support all formats. - if (0 < $imageType) { - return $this->generatePrevieWithGD($path); + try { + $imageType = exif_imagetype($path); + if ($imageType > 0) { + $this->logger->debug('generating preview of ' . $file->getId() . ' with dimension ' . self::TEMP_FILE_DIMENSION . ' using gdlib'); + return $this->generatePreviewWithGD($path); } else { - if (!$this->previewProvider->isAvailable($file)) { - return $path; - } - return $this->generatePreviewWithProvider($file); + return $path; } - } catch(\Throwable $e) { - $this->logger->warning('Failed to generate preview of ' . $file->getId() . ' with dimension '.self::TEMP_FILE_DIMENSION . ': ' . $e->getMessage()); + } catch (\Throwable $e) { + $this->logger->warning('Failed to generate preview of ' . $file->getId() . ' with dimension ' . self::TEMP_FILE_DIMENSION . ' with gdlib: ' . $e->getMessage()); return $path; } } @@ -347,7 +352,7 @@ public function generatePreviewWithProvider(File $file): string { * @return string * @throws \OCA\Recognize\Exception\Exception */ - public function generatePrevieWithGD(string $path): string { + public function generatePreviewWithGD(string $path): string { $image = imagecreatefromstring(file_get_contents($path)); $width = imagesx($image); $height = imagesy($image);