You are here

public function AvatarBase::setDimensions in Avatar Kit 8

Sets dimensions to get form the endpoint.

Parameters

int $width: The width of the avatar.

int|null $height: The height of the avatar, or NULL to mirror value for width.

Return value

\Drupal\avatars\AvatarBaseInterface Returns the called Robohash object for chaining.

Throws

\Drupal\avatars\Exception\AvatarException Thrown if the passed dimensions are invalid.

Overrides AvatarBaseInterface::setDimensions

File

src/AvatarBase.php, line 167

Class

AvatarBase
Abstract class for Avatar APIs.

Namespace

Drupal\avatars

Code

public function setDimensions($width, $height = NULL) {
  if ($this->dimension_width_maximum && $width > $this->dimension_width_maximum) {
    throw new AvatarException('Avatar width is too large.');
  }
  if ($this->dimension_width_minimum && $width < $this->dimension_width_minimum) {
    throw new AvatarException('Avatar width is too small.');
  }
  if ($this->dimension_height_maximum && $height > $this->dimension_height_maximum) {
    throw new AvatarException('Avatar height is too large.');
  }
  if ($this->dimension_height_minimum && $height < $this->dimension_height_minimum) {
    throw new AvatarException('Avatar height is too small.');
  }
  $this->width = $width;
  $this->height = $height === NULL ? $this->width : $height;
  return $this;
}