server/lib/private/preview/pdf.php

41 lines
969 B
PHP
Raw Normal View History

2013-05-09 21:59:16 +00:00
<?php
/**
2013-05-17 10:00:32 +00:00
* Copyright (c) 2013 Georg Ehrke georg@ownCloud.com
2013-05-09 21:59:16 +00:00
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
2013-05-29 10:33:24 +00:00
namespace OC\Preview;
2014-02-14 10:23:39 +00:00
if (extension_loaded('imagick') && count(@\Imagick::queryFormats("PDF")) === 1) {
2013-05-09 21:59:16 +00:00
2013-05-29 11:11:43 +00:00
class PDF extends Provider {
2013-05-28 09:59:20 +00:00
2013-05-29 11:03:33 +00:00
public function getMimeType() {
2013-05-28 09:59:20 +00:00
return '/application\/pdf/';
}
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
2013-07-30 10:29:12 +00:00
$tmpPath = $fileview->toTmpFile($path);
2013-05-09 21:59:16 +00:00
2013-05-28 09:59:20 +00:00
//create imagick object from pdf
2013-05-30 09:06:52 +00:00
try{
2013-07-30 10:29:12 +00:00
$pdf = new \imagick($tmpPath . '[0]');
2013-05-30 09:06:52 +00:00
$pdf->setImageFormat('jpg');
2013-07-30 11:43:15 +00:00
} catch (\Exception $e) {
2013-05-30 09:06:52 +00:00
\OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR);
return false;
}
2013-05-17 17:08:16 +00:00
2013-07-30 10:29:12 +00:00
unlink($tmpPath);
2013-05-09 21:59:16 +00:00
2013-05-28 09:59:20 +00:00
//new image object
$image = new \OC_Image($pdf);
//check if image object is valid
2013-06-11 08:56:16 +00:00
return $image->valid() ? $image : false;
2013-05-28 09:59:20 +00:00
}
2013-05-09 21:59:16 +00:00
}
\OC\Preview::registerProvider('OC\Preview\PDF');
2013-05-28 09:59:20 +00:00
}