当前位置: 首页>>代码示例>>PHP>>正文


PHP OC_Image::loadFromData方法代码示例

本文整理汇总了PHP中OC_Image::loadFromData方法的典型用法代码示例。如果您正苦于以下问题:PHP OC_Image::loadFromData方法的具体用法?PHP OC_Image::loadFromData怎么用?PHP OC_Image::loadFromData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OC_Image的用法示例。


在下文中一共展示了OC_Image::loadFromData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getThumbnail

 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;
 }
开发者ID:WYSAC,项目名称:oregon-owncloud,代码行数:25,代码来源:svg.php

示例2: getThumbnail

 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;
 }
开发者ID:olucao,项目名称:owncloud-core,代码行数:29,代码来源:office-cl.php

示例3: getThumbnail

 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;
 }
开发者ID:olucao,项目名称:owncloud-core,代码行数:25,代码来源:unknown.php

示例4: getThumbnail

 /**
  * {@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;
 }
开发者ID:loulancn,项目名称:core,代码行数:38,代码来源:office.php

示例5: get

 /**
  * 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;
 }
开发者ID:olucao,项目名称:owncloud-core,代码行数:19,代码来源:avatar.php

示例6: getThumbnail

 /**
  * {@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();
 }
开发者ID:heldernl,项目名称:owncloud8-extended,代码行数:18,代码来源:mp3.php

示例7: getThumbnail

 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;
 }
开发者ID:RavenB,项目名称:owncloud-apps,代码行数:16,代码来源:epub-preview.php

示例8: getThumbnail

 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;
 }
开发者ID:omusico,项目名称:isle-web-framework,代码行数:16,代码来源:image.php

示例9: getThumbnail

 /**
  * {@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();
 }
开发者ID:stweil,项目名称:owncloud-core,代码行数:23,代码来源:MP3.php

示例10: getThumbnail

 /**
  * {@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;
 }
开发者ID:evanjt,项目名称:core,代码行数:23,代码来源:bitmap.php

示例11: getThumbnail

 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;
 }
开发者ID:omusico,项目名称:isle-web-framework,代码行数:20,代码来源:office-fallback.php

示例12: toVcard

 /**
  * 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;
 }
开发者ID:seanbradley28,项目名称:gsync,代码行数:60,代码来源:contact.php

示例13: isset

/**
 * ownCloud - Image generator for contacts.
 *
 * @author Thomas Tanghus
 * @copyright 2012 Thomas Tanghus <thomas@tanghus.net>
 *
 * 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();
开发者ID:CDN-Sparks,项目名称:owncloud,代码行数:30,代码来源:tmpphoto.php

示例14: updateImageProperty

 /**
  * @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());
 }
开发者ID:CDN-Sparks,项目名称:owncloud,代码行数:17,代码来源:importconnector.php

示例15: postAvatar

 /**
  * @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);
     }
 }
开发者ID:rchicoli,项目名称:owncloud-core,代码行数:59,代码来源:AvatarController.php


注:本文中的OC_Image::loadFromData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。