Nextcloud PHP API (master)

IAvatar

This class provides avatar functionality

Tags
since
6.0.0

Table of Contents

Methods

avatarBackgroundColor()  : Color
Get the avatar background color
exists()  : bool
Check if an avatar exists for the user
get()  : false|IImage
Get the users avatar
getFile()  : ISimpleFile
Get the file of the avatar
isCustomAvatar()  : bool
Check if the avatar of a user is a custom uploaded one
remove()  : void
Remove the user's avatar
set()  : void
Sets the users avatar
userChanged()  : void
Updates the display name if changed.

Methods

avatarBackgroundColor()

Get the avatar background color

public avatarBackgroundColor(string $hash) : Color
Parameters
$hash : string
Tags
since
14.0.0
Return values
Color

exists()

Check if an avatar exists for the user

public exists() : bool
Tags
since
8.1.0
Return values
bool

get()

Get the users avatar

public get([int $size = 64 ][, bool $darkTheme = false ]) : false|IImage
Parameters
$size : int = 64

size in px of the avatar, avatars are square, defaults to 64, -1 can be used to not scale the image

$darkTheme : bool = false

Should the generated avatar be dark themed

Tags
since
6.0.0
  • size of -1 was added in 9.0.0
Return values
false|IImage

containing the avatar or false if there's no image

getFile()

Get the file of the avatar

public getFile(int $size[, bool $darkTheme = false ]) : ISimpleFile
Parameters
$size : int

The desired image size. -1 can be used to not scale the image

$darkTheme : bool = false

Should the generated avatar be dark themed

Tags
throws
NotFoundException
since
9.0.0
Return values
ISimpleFile

isCustomAvatar()

Check if the avatar of a user is a custom uploaded one

public isCustomAvatar() : bool
Tags
since
14.0.0
Return values
bool

remove()

Remove the user's avatar

public remove([bool $silent = false ]) : void
Parameters
$silent : bool = false

Whether removing the avatar should trigger a change

Tags
since
6.0.0

set()

Sets the users avatar

public set(IImage|resource|string $data) : void
Parameters
$data : IImage|resource|string

An image object, imagedata or path to set a new avatar

Tags
throws
Exception

if the provided file is not a jpg or png image

throws
Exception

if the provided image is not valid

throws
NotSquareException

if the image is not square

since
6.0.0

userChanged()

Updates the display name if changed.

public userChanged(string $feature, mixed $oldValue, mixed $newValue) : void
Parameters
$feature : string

The changed feature

$oldValue : mixed

The previous value

$newValue : mixed

The new value

Tags
since
13.0.0

        
On this page

Search results