Merge pull request #7570 from owncloud/fix_issue_imagick_non_static_4

fix issue with Non-static method Imagick ../..; @ doesn't seem to work in this case
This commit is contained in:
Vincent Petry 2014-03-06 14:11:44 +01:00
commit bfd0d799d8
3 changed files with 80 additions and 62 deletions

View File

@ -6,24 +6,29 @@
* See the COPYING-README file. * See the COPYING-README file.
*/ */
//both, libreoffice backend and php fallback, need imagick //both, libreoffice backend and php fallback, need imagick
if (extension_loaded('imagick') && count(@\Imagick::queryFormats("PDF")) === 1) { if (extension_loaded('imagick')) {
$isShellExecEnabled = \OC_Helper::is_function_enabled('shell_exec');
// LibreOffice preview is currently not supported on Windows $checkImagick = new Imagick();
if (!\OC_Util::runningOnWindows()) {
$whichLibreOffice = ($isShellExecEnabled ? shell_exec('command -v libreoffice') : ''); if(count($checkImagick->queryFormats('PDF')) === 1) {
$isLibreOfficeAvailable = !empty($whichLibreOffice); $isShellExecEnabled = \OC_Helper::is_function_enabled('shell_exec');
$whichOpenOffice = ($isShellExecEnabled ? shell_exec('command -v libreoffice') : '');
$isOpenOfficeAvailable = !empty($whichOpenOffice); // LibreOffice preview is currently not supported on Windows
//let's see if there is libreoffice or openoffice on this machine if (!\OC_Util::runningOnWindows()) {
if($isShellExecEnabled && ($isLibreOfficeAvailable || $isOpenOfficeAvailable || is_string(\OC_Config::getValue('preview_libreoffice_path', null)))) { $whichLibreOffice = ($isShellExecEnabled ? shell_exec('command -v libreoffice') : '');
require_once('office-cl.php'); $isLibreOfficeAvailable = !empty($whichLibreOffice);
}else{ $whichOpenOffice = ($isShellExecEnabled ? shell_exec('command -v libreoffice') : '');
$isOpenOfficeAvailable = !empty($whichOpenOffice);
//let's see if there is libreoffice or openoffice on this machine
if($isShellExecEnabled && ($isLibreOfficeAvailable || $isOpenOfficeAvailable || is_string(\OC_Config::getValue('preview_libreoffice_path', null)))) {
require_once('office-cl.php');
}else{
//in case there isn't, use our fallback
require_once('office-fallback.php');
}
} else {
//in case there isn't, use our fallback //in case there isn't, use our fallback
require_once('office-fallback.php'); require_once('office-fallback.php');
} }
} else {
//in case there isn't, use our fallback
require_once('office-fallback.php');
} }
} }

View File

@ -7,34 +7,41 @@
*/ */
namespace OC\Preview; namespace OC\Preview;
if (extension_loaded('imagick') && count(@\Imagick::queryFormats("PDF")) === 1) { use Imagick;
class PDF extends Provider { if (extension_loaded('imagick')) {
public function getMimeType() { $checkImagick = new Imagick();
return '/application\/pdf/';
}
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { if(count($checkImagick->queryFormats('PDF')) === 1) {
$tmpPath = $fileview->toTmpFile($path);
//create imagick object from pdf class PDF extends Provider {
try{
$pdf = new \imagick($tmpPath . '[0]'); public function getMimeType() {
$pdf->setImageFormat('jpg'); return '/application\/pdf/';
} catch (\Exception $e) {
\OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR);
return false;
} }
unlink($tmpPath); public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
$tmpPath = $fileview->toTmpFile($path);
//new image object //create imagick object from pdf
$image = new \OC_Image($pdf); try{
//check if image object is valid $pdf = new Imagick($tmpPath . '[0]');
return $image->valid() ? $image : false; $pdf->setImageFormat('jpg');
} catch (\Exception $e) {
\OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR);
return false;
}
unlink($tmpPath);
//new image object
$image = new \OC_Image($pdf);
//check if image object is valid
return $image->valid() ? $image : false;
}
} }
}
\OC\Preview::registerProvider('OC\Preview\PDF'); \OC\Preview::registerProvider('OC\Preview\PDF');
}
} }

View File

@ -7,40 +7,46 @@
*/ */
namespace OC\Preview; namespace OC\Preview;
if (extension_loaded('imagick') && count(@\Imagick::queryFormats("SVG")) === 1) { use Imagick;
class SVG extends Provider { if (extension_loaded('imagick')) {
public function getMimeType() { $checkImagick = new Imagick();
return '/image\/svg\+xml/';
}
public function getThumbnail($path,$maxX,$maxY,$scalingup,$fileview) { if(count($checkImagick->queryFormats('SVG')) === 1) {
try{
$svg = new \Imagick();
$svg->setBackgroundColor(new \ImagickPixel('transparent'));
$content = stream_get_contents($fileview->fopen($path, 'r')); class SVG extends Provider {
if(substr($content, 0, 5) !== '<?xml') {
$content = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . $content;
}
$svg->readImageBlob($content); public function getMimeType() {
$svg->setImageFormat('png32'); return '/image\/svg\+xml/';
} catch (\Exception $e) {
\OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR);
return false;
} }
public function getThumbnail($path,$maxX,$maxY,$scalingup,$fileview) {
try{
$svg = new Imagick();
$svg->setBackgroundColor(new \ImagickPixel('transparent'));
//new image object $content = stream_get_contents($fileview->fopen($path, 'r'));
$image = new \OC_Image(); if(substr($content, 0, 5) !== '<?xml') {
$image->loadFromData($svg); $content = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . $content;
//check if image object is valid }
return $image->valid() ? $image : false;
$svg->readImageBlob($content);
$svg->setImageFormat('png32');
} catch (\Exception $e) {
\OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR);
return false;
}
//new image object
$image = new \OC_Image();
$image->loadFromData($svg);
//check if image object is valid
return $image->valid() ? $image : false;
}
} }
\OC\Preview::registerProvider('OC\Preview\SVG');
} }
\OC\Preview::registerProvider('OC\Preview\SVG');
} }