Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh: Use gdlib for preview generation by default #1035

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 && $this->config->getSystemValueString('recognize.preview.gd', 'true') === 'true') {
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
Loading