Skip to content

Commit

Permalink
fix: Use IPreview by default, then fall back to gd
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Klehr <[email protected]>
  • Loading branch information
marcelklehr committed Nov 19, 2023
1 parent ae51e44 commit 5493822
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions lib/Classifiers/Classifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 5493822

Please sign in to comment.