Пример #1
0
 /**
  * @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;
 }
Пример #2
0
 /**
  * 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;
 }
Пример #3
0
 /**
  * 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;
 }
Пример #4
0
 /**
  * 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());
 }
Пример #5
0
 /**
  * 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();
     }
 }
Пример #6
0
 public function getMimeType()
 {
     return $this->image->mimeType();
 }