コード例 #1
0
ファイル: avatar.php プロジェクト: olucao/owncloud-core
 /**
  * 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);
 }
コード例 #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
ファイル: image.php プロジェクト: olucao/owncloud-core
 public function testFitIn()
 {
     $img = new \OC_Image(OC::$SERVERROOT . '/tests/data/testimage.png');
     $this->assertTrue($img->fitIn(200, 100));
     $this->assertEquals(100, $img->width());
     $this->assertEquals(100, $img->height());
     $img = new \OC_Image(file_get_contents(OC::$SERVERROOT . '/tests/data/testimage.jpg'));
     $this->assertTrue($img->fitIn(840, 840));
     $this->assertEquals(840, $img->width());
     $this->assertEquals(525, $img->height());
     $img = new \OC_Image(base64_encode(file_get_contents(OC::$SERVERROOT . '/tests/data/testimage.gif')));
     $this->assertTrue($img->fitIn(200, 250));
     $this->assertEquals(200, $img->width());
     $this->assertEquals(200, $img->height());
 }
コード例 #4
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);
}
コード例 #5
0
ファイル: ImageTest.php プロジェクト: rchicoli/owncloud-core
 /**
  * @dataProvider largeSampleProvider
  *
  * @param string $filename
  * @param int[] $asked
  * @param int[] $expected
  */
 public function testScaleDownWhenBigger($filename, $asked, $expected)
 {
     $img = new \OC_Image(OC::$SERVERROOT . '/tests/data/' . $filename);
     //$this->assertTrue($img->scaleDownToFit($asked[0], $asked[1]));
     $img->scaleDownToFit($asked[0], $asked[1]);
     $this->assertEquals($expected[0], $img->width());
     $this->assertEquals($expected[1], $img->height());
 }
コード例 #6
0
ファイル: photo.php プロジェクト: noci2012/owncloud
if (is_null($contact)) {
    OCP\Util::writeLog('contacts', 'photo.php. The VCard for ID ' . $id . ' is not RFC compatible', OCP\Util::ERROR);
} else {
    OCP\Response::enableCaching($caching);
    OC_Contacts_App::setLastModifiedHeader($contact);
    // Photo :-)
    if ($image->loadFromBase64($contact->getAsString('PHOTO'))) {
        // OK
        OCP\Response::setETagHeader(md5($contact->getAsString('PHOTO')));
    } else {
        // Logo :-/
        if ($image->loadFromBase64($contact->getAsString('LOGO'))) {
            // OK
            OCP\Response::setETagHeader(md5($contact->getAsString('LOGO')));
        }
    }
    if ($image->valid()) {
        $max_size = 200;
        if ($image->width() > $max_size || $image->height() > $max_size) {
            $image->resize($max_size);
        }
    }
}
if (!$image->valid()) {
    // Not found :-(
    getStandardImage();
    //$image->loadFromFile('img/person_large.png');
}
header('Content-Type: ' . $image->mimeType());
$image->show();
//echo OC_Contacts_App::$l10n->t('This card does not contain a photo.');
コード例 #7
0
ファイル: savecrop.php プロジェクト: netcon-source/apps
$w = isset($_POST['w']) && $_POST['w'] ? $_POST['w'] : -1;
$h = isset($_POST['h']) && $_POST['h'] ? $_POST['h'] : -1;
$tmpkey = isset($_POST['tmpkey']) ? $_POST['tmpkey'] : '';
$id = isset($_POST['id']) ? $_POST['id'] : '';
if ($tmpkey == '') {
    bailOut('Missing key to temporary file.');
}
if ($id == '') {
    bailOut('Missing contact id.');
}
OCP\Util::writeLog('contacts', 'savecrop.php: key: ' . $tmpkey, OCP\Util::DEBUG);
$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);
                        bailOut(OCA\Contacts\App::$l10n->t('Error getting PHOTO property.'));
コード例 #8
0
ファイル: savecrop.php プロジェクト: blablubli/owncloudapps
$w = isset($_POST['w']) && $_POST['w'] ? $_POST['w'] : -1;
$h = isset($_POST['h']) && $_POST['h'] ? $_POST['h'] : -1;
$tmpkey = isset($_POST['tmpkey']) ? $_POST['tmpkey'] : '';
$id = isset($_POST['id']) ? $_POST['id'] : '';
if ($tmpkey == '') {
    bailOut('Missing key to temporary file.');
}
if ($id == '') {
    bailOut('Missing contact id.');
}
OCP\Util::writeLog('contacts', 'savecrop.php: key: ' . $tmpkey, OCP\Util::DEBUG);
$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 = OC_Contacts_App::getContactVCard($id);
                if (!$vcard) {
                    OC_Cache::remove($tmpkey);
                    bailOut(OC_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);
                        bailOut(OC_Contacts_App::$l10n->t('Error getting PHOTO property.'));
コード例 #9
0
ファイル: savecrop.php プロジェクト: noci2012/owncloud
//$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')) {
                        OCP\Util::writeLog('contacts', 'savecrop.php: PHOTO property exists.', OCP\Util::DEBUG);
コード例 #10
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;
 }