コード例 #1
0
 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;
 }
コード例 #2
0
ファイル: Image.php プロジェクト: rchicoli/owncloud-core
 /**
  * {@inheritDoc}
  */
 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();
     $useTempFile = $fileInfo->isEncrypted() || !$fileInfo->getStorage()->isLocal();
     if ($useTempFile) {
         $fileName = $fileview->toTmpFile($path);
     } else {
         $fileName = $fileview->getLocalFile($path);
     }
     $image->loadFromFile($fileName);
     $image->fixOrientation();
     if ($useTempFile) {
         unlink($fileName);
     }
     if ($image->valid()) {
         $image->scaleDownToFit($maxX, $maxY);
         return $image;
     }
     return false;
 }
コード例 #3
0
ファイル: movies.php プロジェクト: omusico/isle-web-framework
 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;
 }
コード例 #4
0
ファイル: MP3.php プロジェクト: stweil/owncloud-core
 /**
  * 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;
 }
コード例 #5
0
ファイル: controller.php プロジェクト: samj1912/repo
 public static function postAvatar($args)
 {
     \OC_JSON::checkLoggedIn();
     \OC_JSON::callCheck();
     $user = \OC_User::getUser();
     if (isset($_POST['path'])) {
         $path = stripslashes($_POST['path']);
         $view = new \OC\Files\View('/' . $user . '/files');
         $fileInfo = $view->getFileInfo($path);
         if ($fileInfo['encrypted'] === true) {
             $fileName = $view->toTmpFile($path);
         } else {
             $fileName = $view->getLocalFile($path);
         }
     } elseif (!empty($_FILES)) {
         $files = $_FILES['files'];
         if ($files['error'][0] === 0 && is_uploaded_file($files['tmp_name'][0]) && !\OC\Files\Filesystem::isFileBlacklisted($files['tmp_name'][0])) {
             \OC\Cache::set('avatar_upload', file_get_contents($files['tmp_name'][0]), 7200);
             $view = new \OC\Files\View('/' . $user . '/cache');
             $fileName = $view->getLocalFile('avatar_upload');
             unlink($files['tmp_name'][0]);
         }
     } else {
         $l = new \OC_L10n('core');
         \OC_JSON::error(array("data" => array("message" => $l->t("No image or file provided"))));
         return;
     }
     try {
         $image = new \OC_Image();
         $image->loadFromFile($fileName);
         $image->fixOrientation();
         if ($image->valid()) {
             \OC\Cache::set('tmpavatar', $image->data(), 7200);
             \OC_JSON::error(array("data" => "notsquare"));
         } else {
             $l = new \OC_L10n('core');
             $mimeType = $image->mimeType();
             if ($mimeType !== 'image/jpeg' && $mimeType !== 'image/png') {
                 \OC_JSON::error(array("data" => array("message" => $l->t("Unknown filetype"))));
             }
             if (!$image->valid()) {
                 \OC_JSON::error(array("data" => array("message" => $l->t("Invalid image"))));
             }
         }
     } catch (\Exception $e) {
         \OC_JSON::error(array("data" => array("message" => $e->getMessage())));
     }
 }
コード例 #6
0
ファイル: image.php プロジェクト: omusico/isle-web-framework
 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;
 }
コード例 #7
0
ファイル: image.php プロジェクト: olucao/owncloud-core
 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;
 }
コード例 #8
0
ファイル: movies.php プロジェクト: olucao/owncloud-core
 /**
  * @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;
 }
コード例 #9
0
ファイル: image.php プロジェクト: droiter/openwrt-on-android
 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;
 }
コード例 #10
0
ファイル: movie.php プロジェクト: TechArea/core
 /**
  * @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;
 }
コード例 #11
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);
         $view = new \OC\Files\View('/' . $userId . '/files');
         if ($view->filesize($path) > 20 * 1024 * 1024) {
             return new DataResponse(['data' => ['message' => $this->l->t('File is too big')]], Http::STATUS_BAD_REQUEST);
         }
         $fileName = $view->getLocalFile($path);
     } 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);
             $view = new \OC\Files\View('/' . $userId . '/cache');
             $fileName = $view->getLocalFile('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->loadFromFile($fileName);
         $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()]]);
     }
 }
コード例 #12
0
ファイル: preview.php プロジェクト: unrealbato/core
 /**
  * Defines the media icon, for the media type of the original file, as the preview
  */
 private function getMimeIcon()
 {
     $image = new \OC_Image();
     $mimeIconWebPath = \OC_Helper::mimetypeIcon($this->mimeType);
     if (empty(\OC::$WEBROOT)) {
         $mimeIconServerPath = \OC::$SERVERROOT . $mimeIconWebPath;
     } else {
         $mimeIconServerPath = str_replace(\OC::$WEBROOT, \OC::$SERVERROOT, $mimeIconWebPath);
     }
     $image->loadFromFile($mimeIconServerPath);
     $this->preview = $image;
 }
コード例 #13
0
    bailOut(OC_Contacts_App::$l10n->t('No contact ID was submitted.'));
}
if (!isset($_GET['path'])) {
    bailOut(OC_Contacts_App::$l10n->t('No photo path was submitted.'));
}
$localpath = OC_Filesystem::getLocalFile($_GET['path']);
$tmpfname = tempnam(get_temp_dir(), "occOrig");
if (!file_exists($localpath)) {
    bailOut(OC_Contacts_App::$l10n->t('File doesn\'t exist:') . $localpath);
}
file_put_contents($tmpfname, file_get_contents($localpath));
$image = new OC_Image();
if (!$image) {
    bailOut(OC_Contacts_App::$l10n->t('Error loading image.'));
}
if (!$image->loadFromFile($tmpfname)) {
    bailOut(OC_Contacts_App::$l10n->t('Error loading image.'));
}
if ($image->width() > 400 || $image->height() > 400) {
    $image->resize(400);
    // Prettier resizing than with browser and saves bandwidth.
}
if (!$image->fixOrientation()) {
    // No fatal error so we don't bail out.
    debug('Couldn\'t save correct image orientation: ' . $tmpfname);
}
if ($image->save($tmpfname)) {
    OCP\JSON::success(array('data' => array('id' => $_GET['id'], 'tmp' => $tmpfname)));
    exit;
} else {
    bailOut('Couldn\'t save temporary image: ' . $tmpfname);
コード例 #14
0
ファイル: oc_photo.php プロジェクト: blablubli/owncloudapps
if (!isset($_GET['id'])) {
    bailOut(OC_Contacts_App::$l10n->t('No contact ID was submitted.'));
}
if (!isset($_GET['path'])) {
    bailOut(OC_Contacts_App::$l10n->t('No photo path was submitted.'));
}
$localpath = OC_Filesystem::getLocalFile($_GET['path']);
$tmpkey = 'contact-photo-' . $_GET['id'];
if (!file_exists($localpath)) {
    bailOut(OC_Contacts_App::$l10n->t('File doesn\'t exist:') . $localpath);
}
$image = new OC_Image();
if (!$image) {
    bailOut(OC_Contacts_App::$l10n->t('Error loading image.'));
}
if (!$image->loadFromFile($localpath)) {
    bailOut(OC_Contacts_App::$l10n->t('Error loading image.'));
}
if ($image->width() > 400 || $image->height() > 400) {
    $image->resize(400);
    // Prettier resizing than with browser and saves bandwidth.
}
if (!$image->fixOrientation()) {
    // No fatal error so we don't bail out.
    OCP\Util::writeLog('contacts', 'ajax/oc_photo.php: Couldn\'t save correct image orientation: ' . $localpath, OCP\Util::DEBUG);
}
if (OC_Cache::set($tmpkey, $image->data(), 600)) {
    OCP\JSON::success(array('data' => array('id' => $_GET['id'], 'tmp' => $tmpkey)));
    exit;
} else {
    bailOut('Couldn\'t save temporary image: ' . $tmpkey);
コード例 #15
0
ファイル: managers.php プロジェクト: blablubli/owncloudapps
 public function getThumbnailInfo($path)
 {
     $arr = DatabaseManager::getInstance()->getFileData($path);
     if (!$arr) {
         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;
         }
         $arr = DatabaseManager::getInstance()->setFileData($path, $this->getThumbnailWidth($image), self::THUMBNAIL_HEIGHT);
     }
     $ret = array('filepath' => $arr['path'], 'width' => $arr['width'], 'height' => $arr['height']);
     return $ret;
 }
コード例 #16
0
}
if (!isset($_FILES['imagefile'])) {
    OCP\Util::writeLog('contacts', 'ajax/uploadphoto.php: No file was uploaded. Unknown error.', OCP\Util::DEBUG);
    OCP\JSON::error(array('data' => array('message' => 'No file was uploaded. Unknown error')));
    exit;
}
$error = $_FILES['imagefile']['error'];
if ($error !== UPLOAD_ERR_OK) {
    $errors = array(0 => OC_Contacts_App::$l10n->t("There is no error, the file uploaded with success"), 1 => OC_Contacts_App::$l10n->t("The uploaded file exceeds the upload_max_filesize directive in php.ini") . ini_get('upload_max_filesize'), 2 => OC_Contacts_App::$l10n->t("The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form"), 3 => OC_Contacts_App::$l10n->t("The uploaded file was only partially uploaded"), 4 => OC_Contacts_App::$l10n->t("No file was uploaded"), 6 => OC_Contacts_App::$l10n->t("Missing a temporary folder"));
    bailOut($errors[$error]);
}
$file = $_FILES['imagefile'];
$tmpfname = tempnam(get_temp_dir(), "occOrig");
if (file_exists($file['tmp_name'])) {
    $image = new OC_Image();
    if ($image->loadFromFile($file['tmp_name'])) {
        if ($image->width() > 400 || $image->height() > 400) {
            $image->resize(400);
            // Prettier resizing than with browser and saves bandwidth.
        }
        if (!$image->fixOrientation()) {
            // No fatal error so we don't bail out.
            debug('Couldn\'t save correct image orientation: ' . $tmpfname);
        }
        if ($image->save($tmpfname)) {
            OCP\JSON::success(array('data' => array('mime' => $file['type'], 'size' => $file['size'], 'name' => $file['name'], 'id' => $_POST['id'], 'tmp' => $tmpfname)));
            exit;
        } else {
            bailOut('Couldn\'t save temporary image: ' . $tmpfname);
        }
    } else {
コード例 #17
0
ファイル: savecrop.php プロジェクト: noci2012/owncloud
$y1 = isset($_POST['y1']) && $_POST['y1'] ? $_POST['y1'] : 0;
//$y2 = isset($_POST['y2']) ? $_POST['y2'] : -1;
$w = isset($_POST['w']) && $_POST['w'] ? $_POST['w'] : -1;
$h = isset($_POST['h']) && $_POST['h'] ? $_POST['h'] : -1;
$tmp_path = isset($_POST['tmp_path']) ? $_POST['tmp_path'] : '';
$id = isset($_POST['id']) ? $_POST['id'] : '';
if ($tmp_path == '') {
    bailOut('Missing path to temporary file.');
}
if ($id == '') {
    bailOut('Missing contact id.');
}
OCP\Util::writeLog('contacts', 'savecrop.php: files: ' . $tmp_path . '  exists: ' . file_exists($tmp_path), OCP\Util::DEBUG);
if (file_exists($tmp_path)) {
    $image = new OC_Image();
    if ($image->loadFromFile($tmp_path)) {
        $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)) {
                $tmpfname = tempnam(get_temp_dir(), "occCropped");
                // create a new file because of caching issues.
                if ($image->save($tmpfname)) {
                    unlink($tmp_path);
                    $card = OC_Contacts_App::getContactVCard($id);
                    if (!$card) {
                        unlink($tmpfname);
                        bailOut('Error getting contact object.');
                    }
                    if ($card->__isset('PHOTO')) {