- Added nullable properties

This commit is contained in:
Dave M. 2026-07-01 12:54:08 -04:00
parent dab73eab9a
commit 90932fc6cc
2 changed files with 14 additions and 14 deletions

View File

@ -26,17 +26,6 @@ class Canvas {
}
}
public function __destruct() {
$this->destroy();
}
public function destroy() : self
{
\is_resource($this->image) && \imagedestroy($this->image);
return $this;
}
public function create(int $width, int $height) : self
{
$this->width = $width;
@ -200,8 +189,18 @@ class Canvas {
unset($src->image);
}
public function constrain(int $width, int $height, bool $immutable = true) : self
public function constrain(? int $width, ? int $height, bool $immutable = true) : self
{
if ($width === null && $height === null) {
throw new \LogicException("At least one limiting factor must be provided, either width or height (or both).");
}
elseif ($width === null) {
$width = $this->width * ( $height / $this->height );
}
elseif ($height === null) {
$height = $this->height * ( $width / $this->width );
}
if ( ($this->width > $width) || ($this->height > $height) ) {
if ($this->width > $this->height) {
$height = $this->height * ( $width / $this->width );
@ -224,6 +223,7 @@ class Canvas {
}
}
return $this;
}

View File

@ -120,12 +120,12 @@ class Image extends Canvas {
return $img;
}
public function save(int $quality = null, $filters = null) : bool
public function save(? int $quality = null, $filters = null) : bool
{
return $this->render($this->filename, $quality, $filters);
}
public function render(string $path = null, int $quality = null, $filters = null) # : bool
public function render(? string $path = null, ? int $quality = null, $filters = null) # : bool
{
$layers = $this->layers();