52 lines
1.2 KiB
PHP
52 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Aweos\Resizer\Compressors;
|
|
|
|
use Aweos\Resizer\Lib\MediaPath;
|
|
use Illuminate\Support\Collection;
|
|
use Storage;
|
|
|
|
abstract class Compressor
|
|
{
|
|
|
|
protected MediaPath $media;
|
|
|
|
abstract function make(string $path): array;
|
|
abstract protected function getExtension(): string;
|
|
abstract public function getExtensionRegex(): string;
|
|
abstract public function shouldGenerateVersions(): bool;
|
|
abstract public function start(): void;
|
|
abstract public function end(): void;
|
|
abstract public function resize(Collection $size, bool $update, callable $callback): void;
|
|
|
|
public function __construct(MediaPath $media)
|
|
{
|
|
$this->media = $media;
|
|
}
|
|
|
|
public function tmpPath(): string
|
|
{
|
|
return "/tmp/".str_slug(microtime());
|
|
}
|
|
|
|
protected function versionFilename($width, $height): string
|
|
{
|
|
return $this->media->filename().
|
|
'-'.
|
|
$width.
|
|
'x'.
|
|
$height.
|
|
'.'.$this->getExtension();
|
|
}
|
|
|
|
public function moveTo(string $source, string $destination): void
|
|
{
|
|
if (Storage::exists($destination)) {
|
|
Storage::delete($destination);
|
|
}
|
|
|
|
Storage::move($source, $destination);
|
|
}
|
|
|
|
}
|