コード例 #1
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;
 }
コード例 #2
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;
 }
コード例 #3
0
ファイル: sharing.php プロジェクト: noci2012/owncloud
function handleGetAlbumThumbnail($token, $albumname)
{
    $owner = OC_Gallery_Sharing::getTokenOwner($token);
    $file = OCP\Config::getSystemValue("datadirectory") . '/' . $owner . '/gallery/' . $albumname . '.png';
    $image = new OC_Image($file);
    if ($image->valid()) {
        $image->centerCrop();
        $image->resize(200);
        $image->fixOrientation();
        OCP\Response::enableCaching(3600 * 24);
        // 24 hour
        $image->show();
    }
}
コード例 #4
0
ファイル: sharing.php プロジェクト: blablubli/owncloudapps
function handleGetAlbumThumbnail($token, $albumname)
{
    $owner = OC_Gallery_Sharing::getTokenOwner($token);
    $view = OCP\Files::getStorage('gallery');
    $file = $view->fopen($albumname . '.png', 'r');
    $image = new OC_Image($file);
    if ($image->valid()) {
        $image->centerCrop();
        $image->resize(200);
        $image->fixOrientation();
        OCP\Response::enableCaching(3600 * 24);
        // 24 hour
        $image->show();
    }
}
コード例 #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 プロジェクト: pinoniq/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);
     $image->fixOrientation();
     return $image->valid() ? $image : false;
 }
コード例 #7
0
ファイル: image.php プロジェクト: heldernl/owncloud8-extended
 /**
  * {@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();
     if ($fileInfo['encrypted'] === true) {
         $fileName = $fileview->toTmpFile($path);
     } else {
         $fileName = $fileview->getLocalFile($path);
     }
     $image->loadFromFile($fileName);
     $image->fixOrientation();
     return $image->valid() ? $image : false;
 }
コード例 #8
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()]]);
     }
 }
コード例 #9
0
 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;
 }
コード例 #10
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);
     }
 }
コード例 #11
0
ファイル: photo.php プロジェクト: noldmess/apps
 public static function getViewImage($image_name, $owner = null)
 {
     if (!$owner) {
         $owner = OCP\USER::getUser();
     }
     $view_file = OC_Filesystem::getLocalFile($image_name);
     if (!is_dir($save_dir)) {
         mkdir($save_dir, 0777, true);
     }
     if (file_exists($view_file)) {
         $image = new OC_Image($view_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->resize(1200);
             $image->fixOrientation();
             $image->save($view_file);
         }
     }
     if ($image->valid()) {
         return $image;
     } else {
         $image->destroy();
     }
     return null;
 }
コード例 #12
0
}
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);
}
コード例 #13
0
ファイル: image.php プロジェクト: CDN-Sparks/owncloud
            $img = $sharedGallery . '/' . $img;
        } else {
            $img = $sharedGallery;
        }
    } else {
        OC_JSON::error('no such file');
        die;
    }
}
$mime = $ownerView->getMimeType($img);
list($mimePart, ) = explode('/', $mime);
if ($mimePart === 'image') {
    $local = $ownerView->getLocalFile($img);
    $rotate = false;
    if (is_callable('exif_read_data')) {
        //don't use OC_Image here, using OC_Image will always cause parsing the image file
        $exif = @exif_read_data($local, 'IFD0');
        if (isset($exif['Orientation'])) {
            $rotate = $exif['Orientation'] > 1;
        }
    }
    if ($rotate) {
        $image = new OC_Image($local);
        $image->fixOrientation();
        $image->show();
    } else {
        //use the original file if we dont need to rotate, saves having to re-encode the image
        header('Content-Type: ' . $mime);
        $ownerView->readfile($img);
    }
}
コード例 #14
0
ファイル: managers.php プロジェクト: blablubli/owncloudapps
 public function getThumbnail($path)
 {
     $gallery_storage = \OCP\Files::getStorage('gallery');
     if ($gallery_storage->file_exists($path)) {
         return new \OC_Image($gallery_storage->getLocalFile($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(self::THUMBNAIL_HEIGHT * $image->width() / $image->height()), self::THUMBNAIL_HEIGHT);
     if (!$ret) {
         \OC_Log::write(self::TAG, 'Couldn\'t resize image', \OC_Log::ERROR);
         unset($image);
         return false;
     }
     $l = $gallery_storage->getLocalFile($path);
     $image->save($l);
     return $image;
 }