Example #1
0
class Image extends Provider
{
    public function getMimeType()
    {
        return '/image\\/(?!tiff$)(?!svg.*).*/';
    }
    public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
    {
        //get fileinfo
        $fileInfo = $fileview->getFileInfo($path);
        if (!$fileInfo) {
            return false;
        }
        $maxSizeForImages = \OC::$server->getConfig()->getSystemValue('preview_max_filesize_image', 50);
        $size = $fileInfo->getSize();
        if ($maxSizeForImages !== -1 && $size > $maxSizeForImages * 1024 * 1024) {
            return false;
        }
        $image = new \OC_Image();
        if ($fileInfo['encrypted'] === true) {
            $fileName = $fileview->toTmpFile($path);
        } else {
            $fileName = $fileview->getLocalFile($path);
        }
        $image->loadFromFile($fileName);
        return $image->valid() ? $image : false;
    }
}
\OC\Preview::registerProvider('OC\\Preview\\Image');
Example #2
0
        }
        $lines = preg_split("/\r\n|\n|\r/", $content);
        $fontSize = 5;
        //5px
        $lineSize = ceil($fontSize * 1.25);
        $image = imagecreate($maxX, $maxY);
        imagecolorallocate($image, 255, 255, 255);
        $textColor = imagecolorallocate($image, 0, 0, 0);
        foreach ($lines as $index => $line) {
            $index = $index + 1;
            $x = (int) 1;
            $y = (int) ($index * $lineSize) - $fontSize;
            imagestring($image, 1, $x, $y, $line, $textColor);
            if ($index * $lineSize >= $maxY) {
                break;
            }
        }
        $image = new \OC_Image($image);
        return $image->valid() ? $image : false;
    }
}
\OC\Preview::registerProvider('OC\\Preview\\TXT');
class MarkDown extends TXT
{
    public function getMimeType()
    {
        return '/text\\/(x-)?markdown/';
    }
}
\OC\Preview::registerProvider('OC\\Preview\\MarkDown');
Example #3
0
                return '/image\\/svg\\+xml/';
            }
            public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
            {
                try {
                    $svg = new Imagick();
                    $svg->setBackgroundColor(new \ImagickPixel('transparent'));
                    $content = stream_get_contents($fileview->fopen($path, 'r'));
                    if (substr($content, 0, 5) !== '<?xml') {
                        $content = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . $content;
                    }
                    // Do not parse SVG files with references
                    if (stripos($content, 'xlink:href') !== false) {
                        return 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');
    }
}
Example #4
0
        }
    }
    \OC\Preview::registerProvider('OC\\Preview\\MSOffice2003');
    //.docx, .dotx, .xlsx, .xltx, .pptx, .potx, .ppsx
    class MSOffice2007 extends Office
    {
        public function getMimeType()
        {
            return '/application\\/vnd.openxmlformats-officedocument.*/';
        }
    }
    \OC\Preview::registerProvider('OC\\Preview\\MSOffice2007');
    //.odt, .ott, .oth, .odm, .odg, .otg, .odp, .otp, .ods, .ots, .odc, .odf, .odb, .odi, .oxt
    class OpenDocument extends Office
    {
        public function getMimeType()
        {
            return '/application\\/vnd.oasis.opendocument.*/';
        }
    }
    \OC\Preview::registerProvider('OC\\Preview\\OpenDocument');
    //.sxw, .stw, .sxc, .stc, .sxd, .std, .sxi, .sti, .sxg, .sxm
    class StarOffice extends Office
    {
        public function getMimeType()
        {
            return '/application\\/vnd.sun.xml.*/';
        }
    }
    \OC\Preview::registerProvider('OC\\Preview\\StarOffice');
}
Example #5
0
            {
                // TODO: use proc_open() and stream the source file ?
                $absPath = \OC_Helper::tmpFile();
                $tmpPath = \OC_Helper::tmpFile();
                $handle = $fileview->fopen($path, 'rb');
                // we better use 5MB (1024 * 1024 * 5 = 5242880) instead of 1MB.
                // in some cases 1MB was no enough to generate thumbnail
                $firstmb = stream_get_contents($handle, 5242880);
                file_put_contents($absPath, $firstmb);
                if (self::$avconvBinary) {
                    $cmd = self::$avconvBinary . ' -an -y -ss 5' . ' -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1 -vsync 1 ' . escapeshellarg($tmpPath) . ' > /dev/null 2>&1';
                } else {
                    $cmd = self::$ffmpegBinary . ' -y -ss 5' . ' -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1' . ' -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) . ' ' . escapeshellarg($tmpPath) . ' > /dev/null 2>&1';
                }
                exec($cmd, $output, $returnCode);
                unlink($absPath);
                if ($returnCode === 0) {
                    $image = new \OC_Image();
                    $image->loadFromFile($tmpPath);
                    unlink($tmpPath);
                    return $image->valid() ? $image : false;
                }
                return false;
            }
        }
        // a bit hacky but didn't want to use subclasses
        Movie::$avconvBinary = $avconvBinary;
        Movie::$ffmpegBinary = $ffmpegBinary;
        \OC\Preview::registerProvider('OC\\Preview\\Movie');
    }
}
Example #6
0
<?php

$l = OC_L10N::get('files_opds');
require 'files_opds/lib/epub-preview.php';
\OCP\App::registerPersonal('files_opds', 'personal');
\OCP\App::registerAdmin('files_opds', 'admin');
/* register preview provider */
\OC\Preview::registerProvider('OC\\Preview\\Epub');
Example #7
0
    {
        return '/.*/';
    }
    public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
    {
        $mimetype = $fileview->getMimeType($path);
        $path = \OC_Helper::mimetypeIcon($mimetype);
        $path = \OC::$SERVERROOT . substr($path, strlen(\OC::$WEBROOT));
        $svgPath = substr_replace($path, 'svg', -3);
        if (extension_loaded('imagick') && file_exists($svgPath) && count(@\Imagick::queryFormats("SVG")) === 1) {
            // http://www.php.net/manual/de/imagick.setresolution.php#85284
            $svg = new \Imagick();
            $svg->readImage($svgPath);
            $res = $svg->getImageResolution();
            $x_ratio = $res['x'] / $svg->getImageWidth();
            $y_ratio = $res['y'] / $svg->getImageHeight();
            $svg->removeImage();
            $svg->setResolution($maxX * $x_ratio, $maxY * $y_ratio);
            $svg->setBackgroundColor(new \ImagickPixel('transparent'));
            $svg->readImage($svgPath);
            $svg->setImageFormat('png32');
            $image = new \OC_Image();
            $image->loadFromData($svg);
        } else {
            $image = new \OC_Image($path);
        }
        return $image;
    }
}
\OC\Preview::registerProvider('OC\\Preview\\Unknown');
Example #8
0
use Imagick;
if (extension_loaded('imagick')) {
    $checkImagick = new Imagick();
    if (count($checkImagick->queryFormats('TIFF')) === 1) {
        class TIFF extends Provider
        {
            public function getMimeType()
            {
                return '/image\\/tiff/';
            }
            public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
            {
                $tmpPath = $fileview->toTmpFile($path);
                //create imagick object from TIFF
                try {
                    $tiff = new Imagick($tmpPath);
                    $tiff->setImageFormat('png');
                } catch (\Exception $e) {
                    \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR);
                    return false;
                }
                unlink($tmpPath);
                //new image object
                $image = new \OC_Image($tiff);
                //check if image object is valid
                return $image->valid() ? $image : false;
            }
        }
        \OC\Preview::registerProvider('OC\\Preview\\TIFF');
    }
}
Example #9
0
            public function getMimeType()
            {
                return '/application\\/illustrator/';
            }
        }
        \OC\Preview::registerProvider('OC\\Preview\\Illustrator');
    }
    // Requires adding 'eps' => array('application/postscript', null), to lib/private/mimetypes.list.php
    if (count($checkImagick->queryFormats('EPS')) === 1) {
        //.eps
        class Postscript extends Bitmap
        {
            public function getMimeType()
            {
                return '/application\\/postscript/';
            }
        }
        \OC\Preview::registerProvider('OC\\Preview\\Postscript');
    }
    if (count($checkImagick->queryFormats('PSD')) === 1) {
        //.psd
        class Photoshop extends Bitmap
        {
            public function getMimeType()
            {
                return '/application\\/x-photoshop/';
            }
        }
        \OC\Preview::registerProvider('OC\\Preview\\Photoshop');
    }
}
class XLS extends MSOfficeExcel
{
    public function getMimeType()
    {
        return '/application\\/vnd.ms-excel/';
    }
}
\OC\Preview::registerProvider('OC\\Preview\\XLS');
class XLSX extends MSOfficeExcel
{
    public function getMimeType()
    {
        return '/application\\/vnd.openxmlformats-officedocument.spreadsheetml.sheet/';
    }
}
\OC\Preview::registerProvider('OC\\Preview\\XLSX');
/* //There is no (good) php-only solution for converting powerpoint documents to pdfs / pngs ...
class MSOfficePowerPoint extends Provider {

	public function getMimeType() {
		return null;
	}

	public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
		return false;
	}

}

class PPT extends MSOfficePowerPoint {