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

No need to convert to PDF with LibreOffice, just convert to PNG #10198

Merged
merged 1 commit into from
Jul 13, 2018
Merged
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
18 changes: 9 additions & 9 deletions lib/private/Preview/Office.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,24 @@ public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {

$tmpDir = \OC::$server->getTempManager()->getTempBaseDir();

$defaultParameters = ' -env:UserInstallation=file://' . escapeshellarg($tmpDir . '/owncloud-' . \OC_Util::getInstanceId() . '/') . ' --headless --nologo --nofirststartwizard --invisible --norestore --convert-to pdf --outdir ';
$defaultParameters = ' -env:UserInstallation=file://' . escapeshellarg($tmpDir . '/owncloud-' . \OC_Util::getInstanceId() . '/') . ' --headless --nologo --nofirststartwizard --invisible --norestore --convert-to png --outdir ';
$clParameters = \OC::$server->getConfig()->getSystemValue('preview_office_cl_parameters', $defaultParameters);

$exec = $this->cmd . $clParameters . escapeshellarg($tmpDir) . ' ' . escapeshellarg($absPath);

shell_exec($exec);

//create imagick object from pdf
$pdfPreview = null;
//create imagick object from png
$pngPreview = null;
try {
list($dirname, , , $filename) = array_values(pathinfo($absPath));
$pdfPreview = $dirname . '/' . $filename . '.pdf';
$pngPreview = $dirname . '/' . $filename . '.png';

$pdf = new \imagick($pdfPreview . '[0]');
$pdf->setImageFormat('jpg');
$png = new \imagick($pngPreview . '[0]');
$png->setImageFormat('jpg');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? why convert to jpg?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't ask me, that is what the code did originally, too. First it had LibreOffice export to PDF, then converted that to JPG. I just changed that so that it has LibreOffice export to PNG first.

} catch (\Exception $e) {
unlink($absPath);
unlink($pdfPreview);
unlink($pngPreview);
\OC::$server->getLogger()->logException($e, [
'level' => ILogger::ERROR,
'app' => 'core',
Expand All @@ -69,10 +69,10 @@ public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
}

$image = new \OC_Image();
$image->loadFromData($pdf);
$image->loadFromData($png);

unlink($absPath);
unlink($pdfPreview);
unlink($pngPreview);

if ($image->valid()) {
$image->scaleDownToFit($maxX, $maxY);
Expand Down