本文整理汇总了PHP中OC_Image::data方法的典型用法代码示例。如果您正苦于以下问题:PHP OC_Image::data方法的具体用法?PHP OC_Image::data怎么用?PHP OC_Image::data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC_Image
的用法示例。
在下文中一共展示了OC_Image::data方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
/**
* Returns the rendered image
*
* @return string the file
*/
public function render()
{
if ($this->preview instanceof \OC_Image) {
// Uses imagepng() to output the image
return $this->preview->data();
} else {
return $this->preview;
}
}
示例2: testSetAvatar
public function testSetAvatar()
{
$oldFile = $this->getMock('\\OCP\\Files\\File');
$this->folder->method('get')->will($this->returnValueMap([['avatar.jpg', $oldFile], ['avatar.png', $oldFile]]));
$oldFile->expects($this->exactly(2))->method('delete');
$newFile = $this->getMock('\\OCP\\Files\\File');
$this->folder->expects($this->once())->method('newFile')->with('avatar.png')->willReturn($newFile);
$image = new OC_Image(\OC::$SERVERROOT . '/tests/data/testavatar.png');
$newFile->expects($this->once())->method('putContent')->with($image->data());
$this->avatar->set($image->data());
}
示例3: testAvatarApi
public function testAvatarApi()
{
$avatarManager = \OC::$server->getAvatarManager();
$avatar = $avatarManager->getAvatar($this->user);
$this->assertEquals(false, $avatar->get());
$expected = new OC_Image(\OC::$SERVERROOT . '/tests/data/testavatar.png');
$expected->resize(64);
$avatar->set($expected->data());
$this->assertEquals($expected->data(), $avatar->get()->data());
$avatar->remove();
$this->assertEquals(false, $avatar->get());
}
示例4: testRenderWithOcImageInstance
public function testRenderWithOcImageInstance()
{
$resource = file_get_contents(\OC::$SERVERROOT . '/tests/data/testimage.jpg');
$preview = new \OC_Image($resource);
$data = ['name' => 'testimage.jpg', 'mimetype' => 'image/jpeg', 'preview' => $preview];
$imageResponse = new ImageResponse($data);
$response = $imageResponse->render();
$this->assertSame($preview->data(), $response);
}
示例5: getTmpAvatar
/**
* @NoAdminRequired
*
* @return DataResponse|DataDisplayResponse
*/
public function getTmpAvatar()
{
$tmpAvatar = $this->cache->get('tmpAvatar');
if (is_null($tmpAvatar)) {
return new DataResponse(['data' => ['message' => $this->l->t("No temporary profile picture available, try again")]], Http::STATUS_NOT_FOUND);
}
$image = new \OC_Image($tmpAvatar);
$resp = new DataDisplayResponse($image->data(), Http::STATUS_OK, ['Content-Type' => $image->mimeType()]);
$resp->setETag(crc32($image->data()));
$resp->cacheFor(0);
$resp->setLastModified(new \DateTime('now', new \DateTimeZone('GMT')));
return $resp;
}
示例6: testSetAvatar
public function testSetAvatar()
{
$avatarFileJPG = $this->getMock('\\OCP\\Files\\File');
$avatarFileJPG->method('getName')->willReturn('avatar.jpg');
$avatarFileJPG->expects($this->once())->method('delete');
$avatarFilePNG = $this->getMock('\\OCP\\Files\\File');
$avatarFilePNG->method('getName')->willReturn('avatar.png');
$avatarFilePNG->expects($this->once())->method('delete');
$resizedAvatarFile = $this->getMock('\\OCP\\Files\\File');
$resizedAvatarFile->method('getName')->willReturn('avatar.32.jpg');
$resizedAvatarFile->expects($this->once())->method('delete');
$nonAvatarFile = $this->getMock('\\OCP\\Files\\File');
$nonAvatarFile->method('getName')->willReturn('avatarX');
$nonAvatarFile->expects($this->never())->method('delete');
$this->folder->method('search')->with('avatar')->willReturn([$avatarFileJPG, $avatarFilePNG, $resizedAvatarFile, $nonAvatarFile]);
$newFile = $this->getMock('\\OCP\\Files\\File');
$this->folder->expects($this->once())->method('newFile')->with('avatar.png')->willReturn($newFile);
$image = new OC_Image(\OC::$SERVERROOT . '/tests/data/testavatar.png');
$newFile->expects($this->once())->method('putContent')->with($image->data());
$this->avatar->set($image->data());
}
示例7: testToString
/**
* @depends testData
*/
public function testToString()
{
$img = new \OC_Image(OC::$SERVERROOT . '/tests/data/testimage.png');
$expected = base64_encode($img->data());
$this->assertEquals($expected, (string) $img);
$img = new \OC_Image(file_get_contents(OC::$SERVERROOT . '/tests/data/testimage.jpg'));
$expected = base64_encode($img->data());
$this->assertEquals($expected, (string) $img);
$img = new \OC_Image(OC::$SERVERROOT . '/tests/data/testimage.gif');
$expected = base64_encode($img->data());
$this->assertEquals($expected, (string) $img);
}
示例8: bailOut
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);
}
示例9: cacheThumbnail
public static function cacheThumbnail($id, \OC_Image $image = null)
{
if (\OC_Cache::hasKey(self::THUMBNAIL_PREFIX . $id)) {
return \OC_Cache::get(self::THUMBNAIL_PREFIX . $id);
}
if (is_null($image)) {
$vcard = self::getContactVCard($id);
// invalid vcard
if (is_null($vcard)) {
\OCP\Util::writeLog('contacts', __METHOD__ . ' The VCard for ID ' . $id . ' is not RFC compatible', \OCP\Util::ERROR);
return false;
}
$image = new \OC_Image();
if (!isset($vcard->PHOTO)) {
return false;
}
if (!$image->loadFromBase64((string) $vcard->PHOTO)) {
return false;
}
}
if (!$image->centerCrop()) {
\OCP\Util::writeLog('contacts', 'thumbnail.php. Couldn\'t crop thumbnail for ID ' . $id, \OCP\Util::ERROR);
return false;
}
if (!$image->resize(self::THUMBNAIL_SIZE)) {
\OCP\Util::writeLog('contacts', 'thumbnail.php. Couldn\'t resize thumbnail for ID ' . $id, \OCP\Util::ERROR);
return false;
}
// Cache for around a month
\OC_Cache::set(self::THUMBNAIL_PREFIX . $id, $image->data(), 3000000);
\OCP\Util::writeLog('contacts', 'Caching ' . $id, \OCP\Util::DEBUG);
return \OC_Cache::get(self::THUMBNAIL_PREFIX . $id);
}
示例10: testSetAvatar
public function testSetAvatar()
{
$avatarFileJPG = $this->getMock('\\OCP\\Files\\File');
$avatarFileJPG->method('getName')->willReturn('avatar.jpg');
$avatarFileJPG->expects($this->once())->method('delete');
$avatarFilePNG = $this->getMock('\\OCP\\Files\\File');
$avatarFilePNG->method('getName')->willReturn('avatar.png');
$avatarFilePNG->expects($this->once())->method('delete');
$resizedAvatarFile = $this->getMock('\\OCP\\Files\\File');
$resizedAvatarFile->method('getName')->willReturn('avatar.32.jpg');
$resizedAvatarFile->expects($this->once())->method('delete');
$nonAvatarFile = $this->getMock('\\OCP\\Files\\File');
$nonAvatarFile->method('getName')->willReturn('avatarX');
$nonAvatarFile->expects($this->never())->method('delete');
$this->folder->method('getDirectoryListing')->willReturn([$avatarFileJPG, $avatarFilePNG, $resizedAvatarFile, $nonAvatarFile]);
$newFile = $this->getMock('\\OCP\\Files\\File');
$this->folder->expects($this->once())->method('newFile')->with('avatar.png')->willReturn($newFile);
$image = new OC_Image(\OC::$SERVERROOT . '/tests/data/testavatar.png');
$newFile->expects($this->once())->method('putContent')->with($image->data());
// One on remove and once on setting the new avatar
$this->user->expects($this->exactly(2))->method('triggerChange');
$this->avatar->set($image->data());
}
示例11: postCroppedAvatar
public static function postCroppedAvatar($args)
{
\OC_JSON::checkLoggedIn();
\OC_JSON::callCheck();
$user = \OC_User::getUser();
if (isset($_POST['crop'])) {
$crop = $_POST['crop'];
} else {
$l = new \OC_L10n('core');
\OC_JSON::error(array("data" => array("message" => $l->t("No crop data provided"))));
return;
}
$tmpavatar = \OC_Cache::get('tmpavatar');
if (is_null($tmpavatar)) {
$l = new \OC_L10n('core');
\OC_JSON::error(array("data" => array("message" => $l->t("No temporary profile picture available, try again"))));
return;
}
$image = new \OC_Image($tmpavatar);
$image->crop($crop['x'], $crop['y'], $crop['w'], $crop['h']);
try {
$avatar = new \OC_Avatar($user);
$avatar->set($image->data());
// Clean up
\OC_Cache::remove('tmpavatar');
\OC_JSON::success();
} catch (\Exception $e) {
\OC_JSON::error(array("data" => array("message" => $e->getMessage())));
}
}