Skip to content

Commit

Permalink
image wip
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Apr 28, 2023
1 parent 725fdf0 commit 31828c7
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/Conversion/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ public function resize(?int $width = null, ?int $height = null, bool $crop = fal
$originalWidth = $originalHeight;
}

$resource = imagecreatetruecolor($width, $height);
$resource = imagecreatetruecolor((int) $width, (int) $height);

if (in_array($this->type, [IMAGETYPE_PNG, IMAGETYPE_WEBP])) {
imagealphablending($resource, false);
imagesavealpha($resource, true);
imagefill($resource, 0, 0, imagecolorallocatealpha($resource, 0, 0, 0, 127));
}

imagecopyresampled($resource, $this->resource, 0, 0, $x, $y, $width, $height, $originalWidth, $originalHeight);
imagecopyresampled($resource, $this->resource, 0, 0, (int) $x, (int) $y, (int) $width, (int) $height, $originalWidth, $originalHeight);

imagedestroy($this->resource);
$this->resource = $resource;
Expand Down Expand Up @@ -174,22 +174,22 @@ public function save(): void
*/
protected function create(): void
{
switch ($this->type) {
case IMAGETYPE_GIF:
$this->resource = imagecreatefromgif($this->medium->getAbsolutePath());
break;
case IMAGETYPE_JPEG:
$this->resource = imagecreatefromjpeg($this->medium->getAbsolutePath());
break;
case IMAGETYPE_PNG:
$this->resource = imagecreatefrompng($this->medium->getAbsolutePath());
break;
case IMAGETYPE_WEBP:
$this->resource = imagecreatefromwebp($this->medium->getAbsolutePath());
break;
default:
throw new Exception("The file type [{$this->type}] is not supported.");
}
switch ($this->type) {
case IMAGETYPE_GIF:
$this->resource = imagecreatefromgif($this->medium->getAbsolutePath());
break;
case IMAGETYPE_JPEG:
$this->resource = imagecreatefromjpeg($this->medium->getAbsolutePath());
break;
case IMAGETYPE_PNG:
$this->resource = imagecreatefrompng($this->medium->getAbsolutePath());
break;
case IMAGETYPE_WEBP:
$this->resource = imagecreatefromwebp($this->medium->getAbsolutePath());
break;
default:
throw new Exception("The file type [{$this->type}] is not supported.");
}
}

/**
Expand Down

0 comments on commit 31828c7

Please sign in to comment.