IAvatar.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author John Molakvoæ <skjnldsv@protonmail.com>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Robin Appelman <robin@icewind.nl>
  10. * @author Roeland Jago Douma <roeland@famdouma.nl>
  11. *
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. namespace OCP;
  28. use OCP\Files\NotFoundException;
  29. use OCP\Files\SimpleFS\ISimpleFile;
  30. /**
  31. * This class provides avatar functionality
  32. * @since 6.0.0
  33. */
  34. interface IAvatar {
  35. /**
  36. * Get the users avatar
  37. *
  38. * @param int $size size in px of the avatar, avatars are square, defaults to 64, -1 can be used to not scale the image
  39. * @return false|\OCP\IImage containing the avatar or false if there's no image
  40. * @since 6.0.0 - size of -1 was added in 9.0.0
  41. */
  42. public function get(int $size = 64);
  43. /**
  44. * Check if an avatar exists for the user
  45. *
  46. * @since 8.1.0
  47. */
  48. public function exists(): bool;
  49. /**
  50. * Check if the avatar of a user is a custom uploaded one
  51. *
  52. * @since 14.0.0
  53. */
  54. public function isCustomAvatar(): bool;
  55. /**
  56. * Sets the users avatar
  57. *
  58. * @param \OCP\IImage|resource|string $data An image object, imagedata or path to set a new avatar
  59. * @throws \Exception if the provided file is not a jpg or png image
  60. * @throws \Exception if the provided image is not valid
  61. * @throws \OC\NotSquareException if the image is not square
  62. * @since 6.0.0
  63. */
  64. public function set($data): void;
  65. /**
  66. * Remove the user's avatar
  67. *
  68. * @param bool $silent Whether removing the avatar should trigger a change
  69. * @since 6.0.0
  70. */
  71. public function remove(bool $silent = false): void;
  72. /**
  73. * Get the file of the avatar
  74. *
  75. * @param int $size The desired image size. -1 can be used to not scale the image
  76. * @throws NotFoundException
  77. * @since 9.0.0
  78. */
  79. public function getFile(int $size): ISimpleFile;
  80. /**
  81. * Get the avatar background color
  82. *
  83. * @since 14.0.0
  84. */
  85. public function avatarBackgroundColor(string $hash): Color;
  86. /**
  87. * Updates the display name if changed.
  88. *
  89. * @param string $feature The changed feature
  90. * @param mixed $oldValue The previous value
  91. * @param mixed $newValue The new value
  92. * @since 13.0.0
  93. */
  94. public function userChanged(string $feature, $oldValue, $newValue): void;
  95. }