Skip to content

Commit

Permalink
refactor: move save logic to save method
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafaznv committed Dec 21, 2023
1 parent dec2745 commit ab1f14e
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/Storage/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,9 @@ public function resize(string $saveTo, ImageStyle $style): bool
$this->resizeAuto($style->width, $style->height);
}

$isSvg = $this->file->getExtension() === 'svg' || $this->file->getClientOriginalExtension() === 'svg';

if ($this->driverIsLocal) {
$isSvg
? $this->image->toPng()->save($saveTo)
: $this->image->encode()->save($saveTo);
$this->save($saveTo);
}
else {
list($path, $name) = split_larupload_path($saveTo);
Expand All @@ -89,9 +86,7 @@ public function resize(string $saveTo, ImageStyle $style): bool
$tempName = time() . '-' . $name;
$temp = "$tempDir/$tempName";

$isSvg
? $this->image->toPng()->save($temp)
: $this->image->encode()->save($temp);
$this->save($temp);

Storage::disk($this->disk)->putFileAs($path, new File($temp), $name);

Expand Down Expand Up @@ -228,4 +223,19 @@ private function resizeExact(int $width, int $height): void
{
$this->image->resize($width, $height);
}

/**
* Save image file
*
* @param string $path
* @return void
*/
private function save(string $path): void
{
$isSvg = $this->file->getExtension() === 'svg' || $this->file->getClientOriginalExtension() === 'svg';

$isSvg
? $this->image->toPng()->save($path)
: $this->image->encode()->save($path);
}
}

0 comments on commit ab1f14e

Please sign in to comment.