1
0

IAvatar.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCP;
  8. use OCP\Files\NotFoundException;
  9. use OCP\Files\SimpleFS\ISimpleFile;
  10. /**
  11. * This class provides avatar functionality
  12. * @since 6.0.0
  13. */
  14. interface IAvatar {
  15. /**
  16. * Get the users avatar
  17. *
  18. * @param int $size size in px of the avatar, avatars are square, defaults to 64, -1 can be used to not scale the image
  19. * @param bool $darkTheme Should the generated avatar be dark themed
  20. * @return false|\OCP\IImage containing the avatar or false if there's no image
  21. * @since 6.0.0 - size of -1 was added in 9.0.0
  22. */
  23. public function get(int $size = 64, bool $darkTheme = false);
  24. /**
  25. * Check if an avatar exists for the user
  26. *
  27. * @since 8.1.0
  28. */
  29. public function exists(): bool;
  30. /**
  31. * Check if the avatar of a user is a custom uploaded one
  32. *
  33. * @since 14.0.0
  34. */
  35. public function isCustomAvatar(): bool;
  36. /**
  37. * Sets the users avatar
  38. *
  39. * @param \OCP\IImage|resource|string $data An image object, imagedata or path to set a new avatar
  40. * @throws \Exception if the provided file is not a jpg or png image
  41. * @throws \Exception if the provided image is not valid
  42. * @throws \OC\NotSquareException if the image is not square
  43. * @since 6.0.0
  44. */
  45. public function set($data): void;
  46. /**
  47. * Remove the user's avatar
  48. *
  49. * @param bool $silent Whether removing the avatar should trigger a change
  50. * @since 6.0.0
  51. */
  52. public function remove(bool $silent = false): void;
  53. /**
  54. * Get the file of the avatar
  55. *
  56. * @param int $size The desired image size. -1 can be used to not scale the image
  57. * @param bool $darkTheme Should the generated avatar be dark themed
  58. * @throws NotFoundException
  59. * @since 9.0.0
  60. */
  61. public function getFile(int $size, bool $darkTheme = false): ISimpleFile;
  62. /**
  63. * Get the avatar background color
  64. *
  65. * @since 14.0.0
  66. */
  67. public function avatarBackgroundColor(string $hash): Color;
  68. /**
  69. * Updates the display name if changed.
  70. *
  71. * @param string $feature The changed feature
  72. * @param mixed $oldValue The previous value
  73. * @param mixed $newValue The new value
  74. * @since 13.0.0
  75. */
  76. public function userChanged(string $feature, $oldValue, $newValue): void;
  77. }