示例#1
0
 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;
 }
示例#2
0
 public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
 {
     $this->initCmd();
     if (is_null($this->cmd)) {
         return false;
     }
     $absPath = $fileview->toTmpFile($path);
     $tmpDir = get_temp_dir();
     $defaultParameters = ' --headless --nologo --nofirststartwizard --invisible --norestore -convert-to pdf -outdir ';
     $clParameters = \OCP\Config::getSystemValue('preview_office_cl_parameters', $defaultParameters);
     $exec = $this->cmd . $clParameters . escapeshellarg($tmpDir) . ' ' . escapeshellarg($absPath);
     $export = 'export HOME=/' . $tmpDir;
     shell_exec($export . "\n" . $exec);
     //create imagick object from pdf
     try {
         $pdf = new \imagick($absPath . '.pdf' . '[0]');
         $pdf->setImageFormat('jpg');
     } catch (\Exception $e) {
         unlink($absPath);
         unlink($absPath . '.pdf');
         \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR);
         return false;
     }
     $image = new \OC_Image();
     $image->loadFromData($pdf);
     unlink($absPath);
     unlink($absPath . '.pdf');
     return $image->valid() ? $image : false;
 }
示例#3
0
 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;
 }
示例#4
0
文件: office.php 项目: loulancn/core
 /**
  * {@inheritDoc}
  */
 public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
 {
     $this->initCmd();
     if (is_null($this->cmd)) {
         return false;
     }
     $absPath = $fileview->toTmpFile($path);
     $tmpDir = \OC::$server->getTempManager()->getTempBaseDir();
     $defaultParameters = ' -env:UserInstallation=file://' . escapeshellarg($tmpDir . '/owncloud-' . \OC_Util::getInstanceId() . '/') . ' --headless --nologo --nofirststartwizard --invisible --norestore --convert-to pdf --outdir ';
     $clParameters = \OCP\Config::getSystemValue('preview_office_cl_parameters', $defaultParameters);
     $exec = $this->cmd . $clParameters . escapeshellarg($tmpDir) . ' ' . escapeshellarg($absPath);
     shell_exec($exec);
     //create imagick object from pdf
     $pdfPreview = null;
     try {
         list($dirname, , , $filename) = array_values(pathinfo($absPath));
         $pdfPreview = $dirname . '/' . $filename . '.pdf';
         $pdf = new \imagick($pdfPreview . '[0]');
         $pdf->setImageFormat('jpg');
     } catch (\Exception $e) {
         unlink($absPath);
         unlink($pdfPreview);
         \OCP\Util::writeLog('core', $e->getmessage(), \OCP\Util::ERROR);
         return false;
     }
     $image = new \OC_Image();
     $image->loadFromData($pdf);
     unlink($absPath);
     unlink($pdfPreview);
     if ($image->valid()) {
         $image->scaleDownToFit($maxX, $maxY);
         return $image;
     }
     return false;
 }
示例#5
0
 /**
  * get the users avatar
  * @param int $size size in px of the avatar, avatars are square, defaults to 64
  * @return boolean|\OC_Image containing the avatar or false if there's no image
  */
 public function get($size = 64)
 {
     if ($this->view->file_exists('avatar.jpg')) {
         $ext = 'jpg';
     } elseif ($this->view->file_exists('avatar.png')) {
         $ext = 'png';
     } else {
         return false;
     }
     $avatar = new OC_Image();
     $avatar->loadFromData($this->view->file_get_contents('avatar.' . $ext));
     $avatar->resize($size);
     return $avatar;
 }
示例#6
0
 /**
  * {@inheritDoc}
  */
 public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
 {
     $getID3 = new \getID3();
     $tmpPath = $fileview->toTmpFile($path);
     $tags = $getID3->analyze($tmpPath);
     \getid3_lib::CopyTagsToComments($tags);
     if (isset($tags['id3v2']['APIC'][0]['data'])) {
         $picture = @$tags['id3v2']['APIC'][0]['data'];
         unlink($tmpPath);
         $image = new \OC_Image();
         $image->loadFromData($picture);
         return $image->valid() ? $image : $this->getNoCoverThumbnail();
     }
     return $this->getNoCoverThumbnail();
 }
示例#7
0
 public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
 {
     //get fileinfo
     $fileInfo = $fileview->getFileInfo($path);
     if (!$fileInfo) {
         return false;
     }
     $absPath = $fileview->toTmpFile($path);
     $epub = new \OCA\Files_Opds\Epub($absPath);
     $cover = $epub->Cover();
     if ($cover) {
         $image = new \OC_Image();
         $image->loadFromData($cover['data']);
     }
     return $cover !== null && $image->valid() ? $image : false;
 }
示例#8
0
 public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
 {
     //get fileinfo
     $fileInfo = $fileview->getFileInfo($path);
     if (!$fileInfo) {
         return false;
     }
     $image = new \OC_Image();
     //check if file is encrypted
     if ($fileInfo['encrypted'] === true) {
         $image->loadFromData(stream_get_contents($fileview->fopen($path, 'r')));
     } else {
         $image->loadFromFile($fileview->getLocalFile($path));
     }
     return $image->valid() ? $image : false;
 }
示例#9
0
 /**
  * {@inheritDoc}
  */
 public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
 {
     $getID3 = new ID3Parser();
     $tmpPath = $fileview->toTmpFile($path);
     $tags = $getID3->analyze($tmpPath);
     unlink($tmpPath);
     $picture = isset($tags['id3v2']['APIC'][0]['data']) ? $tags['id3v2']['APIC'][0]['data'] : null;
     if (is_null($picture) && isset($tags['id3v2']['PIC'][0]['data'])) {
         $picture = $tags['id3v2']['PIC'][0]['data'];
     }
     if (!is_null($picture)) {
         $image = new \OC_Image();
         $image->loadFromData($picture);
         if ($image->valid()) {
             $image->scaleDownToFit($maxX, $maxY);
             return $image;
         }
     }
     return $this->getNoCoverThumbnail();
 }
示例#10
0
文件: bitmap.php 项目: evanjt/core
 /**
  * {@inheritDoc}
  */
 public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
 {
     $tmpPath = $fileview->toTmpFile($path);
     if (!$tmpPath) {
         return false;
     }
     // Creates \Imagick object from bitmap or vector file
     try {
         $bp = $this->getResizedPreview($tmpPath, $maxX, $maxY);
     } catch (\Exception $e) {
         \OCP\Util::writeLog('core', 'ImageMagick says: ' . $e->getmessage(), \OCP\Util::ERROR);
         return false;
     }
     unlink($tmpPath);
     //new bitmap image object
     $image = new \OC_Image();
     $image->loadFromData($bp);
     //check if image object is valid
     return $image->valid() ? $image : false;
 }
 public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
 {
     require_once 'PHPExcel/Classes/PHPExcel.php';
     require_once 'PHPExcel/Classes/PHPExcel/IOFactory.php';
     $absPath = $fileview->toTmpFile($path);
     $tmpPath = \OC_Helper::tmpFile();
     $rendererName = \PHPExcel_Settings::PDF_RENDERER_DOMPDF;
     $rendererLibraryPath = \OC::$THIRDPARTYROOT . '/3rdparty/dompdf';
     \PHPExcel_Settings::setPdfRenderer($rendererName, $rendererLibraryPath);
     $phpexcel = new \PHPExcel($absPath);
     $excel = \PHPExcel_IOFactory::createWriter($phpexcel, 'PDF');
     $excel->save($tmpPath);
     $pdf = new \imagick($tmpPath . '[0]');
     $pdf->setImageFormat('jpg');
     unlink($absPath);
     unlink($tmpPath);
     $image = new \OC_Image();
     $image->loadFromData($pdf);
     return $image->valid() ? $image : false;
 }
示例#12
0
 /**
  * Parse contact details into the Contact object
  * @param array $contact
  * @return Sabre\VObject\Component 
  */
 public static function toVcard($contact)
 {
     $vcard = new \Sabre\VObject\Component('VCARD');
     $vcard->setUID();
     $vcard = self::_addPropertyStrings($contact, $vcard);
     if (isset($contact[self::CONTACT_PHONE])) {
         foreach ($contact[self::CONTACT_PHONE] as $phone) {
             if (!isset($phone['value'])) {
                 continue;
             }
             $vcard->addProperty(self::CONTACT_PHONE, $phone['value']);
             $line = count($vcard->children) - 1;
             foreach ($phone['type'] as $type) {
                 $vcard->children[$line]->parameters[] = new \Sabre\VObject\Parameter('TYPE', $type);
             }
         }
     }
     if (isset($contact[self::CONTACT_CATEGORIES])) {
         $categories = array();
         foreach ($contact[self::CONTACT_CATEGORIES] as $categoryId) {
             $categoryData = Request::getGroupDetails($categoryId);
             preg_match('/<title>(.*)<\\/title>/i', $categoryData, $matches);
             if (@$matches[1]) {
                 $categories[] = $matches[1];
             }
         }
         if (count($categories)) {
             $vcard->setString(self::CONTACT_CATEGORIES, implode(',', $categories));
         }
     }
     if (isset($contact[self::CONTACT_ADDRESS])) {
         foreach ($contact[self::CONTACT_ADDRESS] as $address) {
             $vcard->addProperty(self::CONTACT_ADDRESS, $address);
             $line = count($vcard->children) - 1;
             $vcard->children[$line]->parameters[] = new \Sabre\VObject\Parameter('TYPE', $address['type']);
         }
     }
     if (isset($contact[self::CONTACT_EMAIL])) {
         foreach ($contact[self::CONTACT_EMAIL] as $email) {
             $vcard->addProperty(self::CONTACT_EMAIL, $email['value']);
             $line = count($vcard->children) - 1;
             $vcard->children[$line]->parameters[] = new \Sabre\VObject\Parameter('TYPE', $email['type']);
         }
     }
     if (isset($contact[self::CONTACT_PHOTO]) && !empty($contact[self::CONTACT_PHOTO])) {
         $data = Request::getContactImage($contact[self::CONTACT_PHOTO]);
         $img = new \OC_Image();
         if ($img->loadFromData($data)) {
             $vcard->addProperty(self::CONTACT_PHOTO, $img->__toString(), array('ENCODING' => 'b', 'TYPE' => $img->mimeType()));
         } else {
             App::log('Unable to parse the image provided by Google. ', \OCP\Util::WARN);
         }
     }
     return $vcard;
 }
示例#13
0
/**
 * ownCloud - Image generator for contacts.
 *
 * @author Thomas Tanghus
 * @copyright 2012 Thomas Tanghus <*****@*****.**>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
$tmpkey = $_GET['tmpkey'];
$maxsize = isset($_GET['maxsize']) ? $_GET['maxsize'] : -1;
header("Cache-Control: no-cache, no-store, must-revalidate");
OCP\Util::writeLog('contacts', 'tmpphoto.php: tmpkey: ' . $tmpkey, OCP\Util::DEBUG);
$image = new OC_Image();
$image->loadFromData(OC_Cache::get($tmpkey));
if ($maxsize != -1) {
    $image->resize($maxsize);
}
$image();
示例#14
0
 /**
  * @brief modifies a vcard property array with the image
  */
 public function updateImageProperty(&$property, $entry, $version = null)
 {
     $image = new \OC_Image();
     $image->loadFromData($entry);
     if (strcmp($version, '4.0') == 0) {
         $type = $image->mimeType();
     } else {
         $arrayType = explode('/', $image->mimeType());
         $type = strtoupper(array_pop($arrayType));
     }
     $property->add('ENCODING', 'b');
     $property->add('TYPE', $type);
     $property->setValue($image->__toString());
 }
示例#15
0
 /**
  * @NoAdminRequired
  *
  * @param string $path
  * @return DataResponse
  */
 public function postAvatar($path)
 {
     $userId = $this->userSession->getUser()->getUID();
     $files = $this->request->getUploadedFile('files');
     $headers = [];
     if ($this->request->isUserAgent([\OC\AppFramework\Http\Request::USER_AGENT_IE_8])) {
         // due to upload iframe workaround, need to set content-type to text/plain
         $headers['Content-Type'] = 'text/plain';
     }
     if (isset($path)) {
         $path = stripslashes($path);
         $node = $this->userFolder->get($path);
         if (!$node instanceof \OCP\Files\File) {
             return new DataResponse(['data' => ['message' => $this->l->t('Please select a file.')]], Http::STATUS_OK, $headers);
         }
         if ($node->getSize() > 20 * 1024 * 1024) {
             return new DataResponse(['data' => ['message' => $this->l->t('File is too big')]], Http::STATUS_BAD_REQUEST, $headers);
         }
         $content = $node->getContent();
     } elseif (!is_null($files)) {
         if ($files['error'][0] === 0 && is_uploaded_file($files['tmp_name'][0]) && !\OC\Files\Filesystem::isFileBlacklisted($files['tmp_name'][0])) {
             if ($files['size'][0] > 20 * 1024 * 1024) {
                 return new DataResponse(['data' => ['message' => $this->l->t('File is too big')]], Http::STATUS_BAD_REQUEST, $headers);
             }
             $this->cache->set('avatar_upload', file_get_contents($files['tmp_name'][0]), 7200);
             $content = $this->cache->get('avatar_upload');
             unlink($files['tmp_name'][0]);
         } else {
             return new DataResponse(['data' => ['message' => $this->l->t('Invalid file provided')]], Http::STATUS_BAD_REQUEST, $headers);
         }
     } else {
         //Add imgfile
         return new DataResponse(['data' => ['message' => $this->l->t('No image or file provided')]], Http::STATUS_BAD_REQUEST, $headers);
     }
     try {
         $image = new \OC_Image();
         $image->loadFromData($content);
         $image->fixOrientation();
         if ($image->valid()) {
             $mimeType = $image->mimeType();
             if ($mimeType !== 'image/jpeg' && $mimeType !== 'image/png') {
                 return new DataResponse(['data' => ['message' => $this->l->t('Unknown filetype')]], Http::STATUS_OK, $headers);
             }
             $this->cache->set('tmpAvatar', $image->data(), 7200);
             return new DataResponse(['data' => 'notsquare'], Http::STATUS_OK, $headers);
         } else {
             return new DataResponse(['data' => ['message' => $this->l->t('Invalid image')]], Http::STATUS_OK, $headers);
         }
     } catch (\Exception $e) {
         $this->logger->logException($e, ['app' => 'core']);
         return new DataResponse(['data' => ['message' => $this->l->t('An error occurred. Please contact your admin.')]], Http::STATUS_OK, $headers);
     }
 }
示例#16
0
 /**
  * @brief modifies a vcard property array with the image
  */
 public function updateVCardImageProperty(&$v_property, $ldap_entry, $version)
 {
     for ($i = 0; $i < count($v_property); $i++) {
         $image = new \OC_Image();
         $image->loadFromData($ldap_entry);
         if (strcmp($version, '4.0') == 0) {
             $type = $image->mimeType();
         } else {
             $arrayType = explode('/', $image->mimeType());
             $type = strtoupper(array_pop($arrayType));
         }
         $v_property[$i]->add('ENCODING', 'b');
         $v_property[$i]->add('TYPE', $type);
         $v_property[$i]->setValue($image->__toString());
     }
 }
示例#17
0
 /**
  * @NoAdminRequired
  *
  * @param string $path
  * @return DataResponse
  */
 public function postAvatar($path)
 {
     $userId = $this->userSession->getUser()->getUID();
     $files = $this->request->getUploadedFile('files');
     if (isset($path)) {
         $path = stripslashes($path);
         $node = $this->userFolder->get($path);
         if ($node->getSize() > 20 * 1024 * 1024) {
             return new DataResponse(['data' => ['message' => $this->l->t('File is too big')]], Http::STATUS_BAD_REQUEST);
         }
         $content = $node->getContent();
     } elseif (!is_null($files)) {
         if ($files['error'][0] === 0 && is_uploaded_file($files['tmp_name'][0]) && !\OC\Files\Filesystem::isFileBlacklisted($files['tmp_name'][0])) {
             if ($files['size'][0] > 20 * 1024 * 1024) {
                 return new DataResponse(['data' => ['message' => $this->l->t('File is too big')]], Http::STATUS_BAD_REQUEST);
             }
             $this->cache->set('avatar_upload', file_get_contents($files['tmp_name'][0]), 7200);
             $content = $this->cache->get('avatar_upload');
             unlink($files['tmp_name'][0]);
         } else {
             return new DataResponse(['data' => ['message' => $this->l->t('Invalid file provided')]], Http::STATUS_BAD_REQUEST);
         }
     } else {
         //Add imgfile
         return new DataResponse(['data' => ['message' => $this->l->t('No image or file provided')]], Http::STATUS_BAD_REQUEST);
     }
     try {
         $image = new \OC_Image();
         $image->loadFromData($content);
         $image->fixOrientation();
         if ($image->valid()) {
             $mimeType = $image->mimeType();
             if ($mimeType !== 'image/jpeg' && $mimeType !== 'image/png') {
                 return new DataResponse(['data' => ['message' => $this->l->t('Unknown filetype')]]);
             }
             $this->cache->set('tmpAvatar', $image->data(), 7200);
             return new DataResponse(['data' => 'notsquare']);
         } else {
             return new DataResponse(['data' => ['message' => $this->l->t('Invalid image')]]);
         }
     } catch (\Exception $e) {
         return new DataResponse(['data' => ['message' => $e->getMessage()]]);
     }
 }
示例#18
0
// For vCard 3.0 the type must be e.g. JPEG or PNG
// For version 4.0 the full mimetype should be used.
// https://tools.ietf.org/html/rfc2426#section-3.1.4
function imageType($version, $mimeType)
{
    if ($version === '4.0') {
        return $mimeType;
    } else {
        $parts = explode('/', $mimeType);
        return strtoupper(array_pop($parts));
    }
}
$data = OC_Cache::get($tmpkey);
if ($data) {
    $image = new OC_Image();
    if ($image->loadFromData($data)) {
        $w = $w != -1 ? $w : $image->width();
        $h = $h != -1 ? $h : $image->height();
        OCP\Util::writeLog('contacts', 'savecrop.php, x: ' . $x1 . ' y: ' . $y1 . ' w: ' . $w . ' h: ' . $h, OCP\Util::DEBUG);
        if ($image->crop($x1, $y1, $w, $h)) {
            if ($image->width() <= 200 && $image->height() <= 200 || $image->resize(200)) {
                $vcard = OCA\Contacts\App::getContactVCard($id);
                if (!$vcard) {
                    OC_Cache::remove($tmpkey);
                    bailOut(OCA\Contacts\App::$l10n->t('Error getting contact object.'));
                }
                if ($vcard->__isset('PHOTO')) {
                    OCP\Util::writeLog('contacts', 'savecrop.php: PHOTO property exists.', OCP\Util::DEBUG);
                    $property = $vcard->__get('PHOTO');
                    if (!$property) {
                        OC_Cache::remove($tmpkey);