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; }
/** * @param string $path * @param int $maxX * @param int $maxY * @param boolean $scalingup * @param \OC\Files\View $fileview * @return bool|\OC_Image */ public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { $content = $fileview->fopen($path, 'r'); $content = stream_get_contents($content); //don't create previews of empty text files if (trim($content) === '') { return false; } $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; }
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { // 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; }
public static function getThumbnail($image_name, $owner = null) { if (!$owner) { $owner = OCP\USER::getUser(); } $save_dir = OCP\Config::getSystemValue("datadirectory") . '/' . $owner . '/gallery/'; $save_dir .= dirname($image_name) . '/'; $image_path = $image_name; $thumb_file = $save_dir . basename($image_name); if (!is_dir($save_dir)) { mkdir($save_dir, 0777, true); } if (file_exists($thumb_file)) { $image = new OC_Image($thumb_file); } else { $image_path = OC_Filesystem::getLocalFile($image_path); if (!file_exists($image_path)) { return null; } $image = new OC_Image($image_path); if ($image->valid()) { $image->centerCrop(200); $image->fixOrientation(); $image->save($thumb_file); } } if ($image->valid()) { return $image; } else { $image->destroy(); } return null; }
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; }
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; }
/** * {@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; }
/** * sets the users avatar * @param \OC_Image|resource|string $data OC_Image, imagedata or path to set a new avatar * @throws Exception if the provided file is not a jpg or png image * @throws Exception if the provided image is not valid * @throws \OC\NotSquareException if the image is not square * @return void */ public function set($data) { if ($data instanceof OC_Image) { $img = $data; $data = $img->data(); } else { $img = new OC_Image($data); } $type = substr($img->mimeType(), -3); if ($type === 'peg') { $type = 'jpg'; } if ($type !== 'jpg' && $type !== 'png') { $l = \OC_L10N::get('lib'); throw new \Exception($l->t("Unknown filetype")); } if (!$img->valid()) { $l = \OC_L10N::get('lib'); throw new \Exception($l->t("Invalid image")); } if (!($img->height() === $img->width())) { throw new \OC\NotSquareException(); } $this->view->unlink('avatar.jpg'); $this->view->unlink('avatar.png'); $this->view->file_put_contents('avatar.' . $type, $data); }
/** * Stub - sends a generic avatar */ public static function sendAvatar() { $uid = self::preDispatch(false); $image = new \OC_Image('iVBORw0KGgoAAAANSUhEUgAAADAAAAAwEAYAAAAHkiXEAAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAABIAAAASABGyWs+AAAACXZwQWcAAAAwAAAAMADO7oxXAAAUWUlEQVR42u1beXBUVfb+3tZLOp21u0nSHbIRQkJYk5QwIhGNLMKAiDiCqGXpaKFSY2mpVTqOC9aUOo4zMjWihcoUboUysqqMDG6MJMAYooQtJJB962ydTi/v9Vt+f1zv73U3aQibOjOcKji5r1/fd9/3nXvuOefeBi7LZbksl+Wy/K8K81MP4GxiNptMDJOQkJ7ucDBMYaHdnprKsnl5RqPRCMTHGwyCAJjNoihJgM83MDA4qGnt7V1dbreq1tW53b29mnbypKZpGqCqP/X7RMvPhoC0NIeDZceNmznziisE4c47y8omTzaZFi9OS0tLS0kZPTo52WYrLJSklBSbLSuL4ywWszkxkec5ThAEgWWDwUBgcFCWvV6Px+1WlN5et7uhAejr6+k5cUJVGxoa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NDo1Ni0wNzowMGFOGmwAAAAldEVYdGRhdGU6Y3JlYXRlADIwMTAtMDItMjBUMjM6MjY6MjQtMDc6MDAuw1DWAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDEwLTAxLTExVDA4OjU3OjQzLTA3OjAwwqyWbAAAADJ0RVh0TGljZW5zZQBodHRwOi8vZW4ud2lraXBlZGlhLm9yZy93aWtpL1B1YmxpY19kb21haW4//erPAAAAJXRFWHRtb2RpZnktZGF0ZQAyMDA5LTExLTI4VDIyOjQ0OjU2LTA3OjAwPv9sWAAAABl0RVh0U291cmNlAFRhbmdvIEljb24gTGlicmFyeVTP7YIAAAA6dEVYdFNvdXJjZV9VUkwAaHR0cDovL3RhbmdvLmZyZWVkZXNrdG9wLm9yZy9UYW5nb19JY29uX0xpYnJhcnm8yK3WAAAAcnRFWHRzdmc6YmFzZS11cmkAZmlsZTovLy9tbnQvb2dyZS9wcml2eS9kb2NzL2ljb25zL29wZW5faWNvbl9saWJyYXJ5LWRldmVsL2ljb25zL3RhbmdvL3N2ZzJwbmcvZW1vdGVzL2ZhY2Utc21pbGUtMi5zdmerBUU8AAAAAElFTkSuQmCC'); \OC_Util::obEnd(); echo $image->show(); }
public function testRenderWithOcImageInstance() { $resource = file_get_contents(\OC::$SERVERROOT . '/tests/data/testimage.jpg'); $preview = new \OC_Image($resource); $data = ['name' => 'testimage.jpg', 'mimetype' => 'image/jpeg', 'preview' => $preview]; $imageResponse = new ImageResponse($data); $response = $imageResponse->render(); $this->assertSame($preview->data(), $response); }
/** * @param $fileId * @param $width * @param $height * * @return object|\PHPUnit_Framework_MockObject_MockObject */ private function mockGetPreview($fileId, $width, $height) { $image = new \OC_Image(file_get_contents(\OC::$SERVERROOT . '/tests/data/testimage.jpg')); $image->preciseResize($width, $height); $preview = $this->getMockBuilder('\\OC\\Preview')->disableOriginalConstructor()->getMock(); $preview->method('getPreview')->willReturn($image); $preview->method('isCached')->willReturn($fileId); return $preview; }
/** * Returns the rendered image * * @return string the file */ public function render() { if ($this->preview instanceof \OC_Image) { // Uses imagepng() to output the image return $this->preview->data(); } else { return $this->preview; } }
/** * Generates a default image when the file has no cover * * @return bool|\OCP\IImage false if the default image is missing or invalid */ private function getNoCoverThumbnail() { $icon = \OC::$SERVERROOT . '/core/img/filetypes/audio.png'; if (!file_exists($icon)) { return false; } $image = new \OC_Image(); $image->loadFromFile($icon); return $image->valid() ? $image : false; }
public function testSetAvatar() { $oldFile = $this->getMock('\\OCP\\Files\\File'); $this->folder->method('get')->will($this->returnValueMap([['avatar.jpg', $oldFile], ['avatar.png', $oldFile]])); $oldFile->expects($this->exactly(2))->method('delete'); $newFile = $this->getMock('\\OCP\\Files\\File'); $this->folder->expects($this->once())->method('newFile')->with('avatar.png')->willReturn($newFile); $image = new OC_Image(\OC::$SERVERROOT . '/tests/data/testavatar.png'); $newFile->expects($this->once())->method('putContent')->with($image->data()); $this->avatar->set($image->data()); }
public function testAvatarApi() { $avatarManager = \OC::$server->getAvatarManager(); $avatar = $avatarManager->getAvatar($this->user); $this->assertEquals(false, $avatar->get()); $expected = new OC_Image(\OC::$SERVERROOT . '/tests/data/testavatar.png'); $expected->resize(64); $avatar->set($expected->data()); $this->assertEquals($expected->data(), $avatar->get()->data()); $avatar->remove(); $this->assertEquals(false, $avatar->get()); }
public function getThumbnail($path) { $gallery_path = \OCP\Config::getSystemValue('datadirectory') . '/' . \OC_User::getUser() . '/gallery'; if (file_exists($gallery_path . $path)) { return new \OC_Image($gallery_path . $path); } if (!\OC_Filesystem::file_exists($path)) { \OC_Log::write(self::TAG, 'File ' . $path . ' don\'t exists', \OC_Log::WARN); return false; } $image = new \OC_Image(); $image->loadFromFile(\OC_Filesystem::getLocalFile($path)); if (!$image->valid()) { return false; } $image->fixOrientation(); $ret = $image->preciseResize(floor(150 * $image->width() / $image->height()), 150); if (!$ret) { \OC_Log::write(self::TAG, 'Couldn\'t resize image', \OC_Log::ERROR); unset($image); return false; } $image->save($gallery_path . '/' . $path); return $image; }
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; }
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { //get fileinfo $fileInfo = $fileview->getFileInfo($path); if (!$fileInfo) { 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; }
/** * show preview * @return void */ public function showPreview($mimeType = null) { \OCP\Response::enableCaching(3600 * 24); // 24 hours if (is_null($this->preview)) { $this->getPreview(); } $this->preview->show($mimeType); }
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; }
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; }
function handleGetThumbnails($albumname) { OCP\Response::enableCaching(3600 * 24); // 24 hour $thumbnail = OC::$CONFIG_DATADIRECTORY . '/../gallery/' . urldecode($albumname) . '.png'; header('Content-Type: ' . OC_Image::getMimeTypeForFile($thumbnail)); OCP\Response::sendFile($thumbnail); }
/** * @param int $maxX * @param int $maxY * @param string $absPath * @param string $tmpPath * @param int $second * @return bool|\OC_Image */ private function generateThumbNail($maxX, $maxY, $absPath, $second) { $tmpPath = \OC_Helper::tmpFile(); if (self::$avconvBinary) { $cmd = self::$avconvBinary . ' -an -y -ss ' . escapeshellarg($second) . ' -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1 -vsync 1 ' . escapeshellarg($tmpPath) . ' > /dev/null 2>&1'; } else { $cmd = self::$ffmpegBinary . ' -y -ss ' . escapeshellarg($second) . ' -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1' . ' -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) . ' ' . escapeshellarg($tmpPath) . ' > /dev/null 2>&1'; } exec($cmd, $output, $returnCode); if ($returnCode === 0) { $image = new \OC_Image(); $image->loadFromFile($tmpPath); unlink($tmpPath); return $image->valid() ? $image : false; } unlink($tmpPath); return false; }
function handleGetThumbnails($albumname) { OCP\Response::enableCaching(3600 * 24); // 24 hour $view = OCP\Files::getStorage('gallery'); $thumbnail = $view->fopen(urldecode($albumname) . '.png', 'r'); header('Content-Type: ' . OC_Image::getMimeTypeForFile($thumbnail)); OCP\Response::sendFile($thumbnail); }
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { $tmpPath = $fileview->toTmpFile($path); //create imagick object from bitmap or vector file try { // Layer 0 contains either the bitmap or // a flat representation of all vector layers $bp = new Imagick($tmpPath . '[0]'); $bp->setImageFormat('png'); } catch (\Exception $e) { \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); return false; } unlink($tmpPath); //new bitmap image object $image = new \OC_Image($bp); //check if image object is valid return $image->valid() ? $image : false; }
/** * @brief show preview * @return void */ public function showPreview() { \OCP\Response::enableCaching(3600 * 24); // 24 hours if (is_null($this->preview)) { $this->getPreview(); } $this->preview->show('image/png'); return; }
/** * {@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; }
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; }
/** * @param int $maxX * @param int $maxY * @param string $absPath * @param int $second * @return bool|\OCP\IImage */ private function generateThumbNail($maxX, $maxY, $absPath, $second) { $tmpPath = \OC::$server->getTempManager()->getTemporaryFile(); if (self::$avconvBinary) { $cmd = self::$avconvBinary . ' -an -y -ss ' . escapeshellarg($second) . ' -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1 -vsync 1 ' . escapeshellarg($tmpPath) . ' > /dev/null 2>&1'; } else { $cmd = self::$ffmpegBinary . ' -y -ss ' . escapeshellarg($second) . ' -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1' . ' ' . escapeshellarg($tmpPath) . ' > /dev/null 2>&1'; } exec($cmd, $output, $returnCode); if ($returnCode === 0) { $image = new \OC_Image(); $image->loadFromFile($tmpPath); unlink($tmpPath); if ($image->valid()) { $image->scaleDownToFit($maxX, $maxY); return $image; } } unlink($tmpPath); return false; }