Skip to content

Instantly share code, notes, and snippets.

@emmadesilva
Created January 21, 2024 07:57
Show Gist options
  • Select an option

  • Save emmadesilva/ca4e8f79fa36481d6b49ca8af5a44b22 to your computer and use it in GitHub Desktop.

Select an option

Save emmadesilva/ca4e8f79fa36481d6b49ca8af5a44b22 to your computer and use it in GitHub Desktop.
enum ImageSizes: string {
case Square = '768x768';
case Portrait = '512x768';
case Landscape = '768x512';
/** @return array{width: int, height: int} */
public function toArray(): array {
$size = explode('x', $this->value);
return [
'width' => (int) $size[0],
'height' => (int) $size[1],
];
}
public function height(): int {
return $this->toArray()['height'];
}
public function width(): int {
return $this->toArray()['width'];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment