/** * @param OCP\Image $image */ public function setImage(\OCP\Image $image) { if (!$image->valid()) { throw new \InvalidArgumentException(__METHOD__ . ' The image resource is not valid.'); } $this->image = $image; $this->addHeader('Content-Type', $image->mimeType()); return $this; }
/** * @brief sets an image as ownCloud avatar * @return null */ private function setOwnCloudAvatar() { if (!$this->image->valid()) { $this->log->log('user_ldap', 'jpegPhoto data invalid for ' . $this->dn, \OCP\Util::ERROR); return; } //make sure it is a square and not bigger than 128x128 $size = min(array($this->image->width(), $this->image->height(), 128)); if (!$this->image->centerCrop($size)) { $this->log->log('user_ldap', 'croping image for avatar failed for ' . $this->dn, \OCP\Util::ERROR); return; } if (!$this->fs->isLoaded()) { $this->fs->setup($this->uid); } $avatar = $this->avatarManager->getAvatar($this->uid); $avatar->set($this->image); }
/** * @brief sets an image as ownCloud avatar * @return null */ private function setOwnCloudAvatar() { if (!$this->image->valid()) { $this->log->log('jpegPhoto data invalid for ' . $this->dn, \OCP\Util::ERROR); return; } //make sure it is a square and not bigger than 128x128 $size = min(array($this->image->width(), $this->image->height(), 128)); if (!$this->image->centerCrop($size)) { $this->log->log('croping image for avatar failed for ' . $this->dn, \OCP\Util::ERROR); return; } if (!$this->fs->isLoaded()) { $this->fs->setup($this->uid); } try { $avatar = $this->avatarManager->getAvatar($this->uid); $avatar->set($this->image); } catch (\Exception $e) { \OC::$server->getLogger()->notice('Could not set avatar for ' . $this->dn . ', because: ' . $e->getMessage(), ['app' => 'user_ldap']); } }
/** * Set the contact photo. * * @param \OCP\Image $photo */ public function setPhoto(\OCP\Image $photo) { // For vCard 3.0 the type must be e.g. JPEG or PNG // For version 4.0 the full mimetype should be used. // https://tools.ietf.org/html/rfc2426#section-3.1.4 if (strval($this->VERSION) === '4.0') { $type = $photo->mimeType(); } else { $type = explode('/', $photo->mimeType()); $type = strtoupper(array_pop($type)); } if (isset($this->PHOTO)) { $property = $this->PHOTO; if (!$property) { return false; } $property->setValue(strval($photo)); $property->parameters = array(); $property->parameters[] = new \Sabre\VObject\Parameter('ENCODING', 'b'); $property->parameters[] = new \Sabre\VObject\Parameter('TYPE', $photo->mimeType()); $this->PHOTO = $property; } else { $this->add('PHOTO', strval($photo), array('ENCODING' => 'b', 'TYPE' => $type)); // TODO: Fix this hack $this->setSaved(false); } return true; }
/** * Set the contact photo. * * @param \OCP\Image $photo */ public function setPhoto(\OCP\Image $photo) { // For vCard 3.0 the type must be e.g. JPEG or PNG // For version 4.0 the full mimetype should be used. // https://tools.ietf.org/html/rfc2426#section-3.1.4 if (strval($this->VERSION) === '4.0') { $type = $photo->mimeType(); } else { $type = explode('/', $photo->mimeType()); $type = strtoupper(array_pop($type)); } if (isset($this->PHOTO)) { $this->remove('PHOTO'); } $this->add('PHOTO', $photo->data(), ['ENCODING' => 'b', 'TYPE' => $type]); $this->setSaved(false); return true; }
/** * Fixes the preview cache by replacing the broken thumbnail with ours * * WARNING: Will break if the thumbnail folder ever moves or if encryption is turned on for * thumbnails * * @param resource $fixedPreview * * @return \OCP\IImage */ private function fixPreviewCache($fixedPreview) { $owner = $this->userId; $file = $this->file; $preview = $this->preview; $fixedPreviewObject = new Image($fixedPreview); // Get the location where the broken thumbnail is stored $thumbnailFolder = $this->dataDir . '/' . $owner . '/'; $thumbnail = $thumbnailFolder . $preview->isCached($file->getId()); // Caching it for next time if ($fixedPreviewObject->save($thumbnail)) { $previewData = $fixedPreviewObject; } else { $previewData = $preview->getPreview(); } return $previewData; }
/** * Fetch the user's avatar */ public function testGetAvatar() { $this->container['UserManager']->expects($this->once())->method('userExists'); $image = new Image(OC::$SERVERROOT . '/tests/data/testimage.jpg'); $this->avatarMock->expects($this->once())->method('get')->willReturn($image); $this->container['AvatarManager']->expects($this->once())->method('getAvatar')->willReturn($this->avatarMock); $response = $this->avatarController->getAvatar($this->user, 32); $this->assertEquals(Http::STATUS_OK, $response->getStatus()); $image2 = new Image($response->getData()); $this->assertEquals($image->mimeType(), $image2->mimeType()); $this->assertEquals(crc32($response->getData()), $response->getEtag()); }
/** * Get contact photo */ public function getPhoto($size = 40) { if (!isset($this->vcard->PHOTO)) { return false; } else { $image = new Image(base64_encode((string) $this->vcard->PHOTO)); $image->resize($size); return 'data:' . $image->mimeType() . ';base64,' . $image->__toString(); } }
public function getMimeType() { return $this->image->mimeType(); }