oc-resizer-plugin/compressors/Compressor.php

52 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2021-09-09 19:18:41 +02:00
<?php
namespace Aweos\Resizer\Compressors;
2021-09-17 14:22:19 +02:00
use Aweos\Resizer\Lib\MediaPath;
2022-02-15 18:15:58 +01:00
use Illuminate\Support\Collection;
2021-09-17 13:31:44 +02:00
use Storage;
2021-09-09 19:18:41 +02:00
abstract class Compressor
{
2021-10-31 22:03:34 +01:00
protected MediaPath $media;
2021-09-17 14:22:19 +02:00
2021-09-09 19:18:41 +02:00
abstract function make(string $path): array;
2022-02-15 18:06:51 +01:00
abstract protected function getExtension(): string;
2021-09-17 17:09:17 +02:00
abstract public function getExtensionRegex(): string;
2022-02-15 18:15:58 +01:00
abstract public function shouldGenerateVersions(): bool;
2022-02-15 18:06:51 +01:00
abstract public function start(): void;
abstract public function end(): void;
2022-02-15 18:15:58 +01:00
abstract public function resize(Collection $size, bool $update, callable $callback): void;
2021-09-17 17:09:17 +02:00
2021-09-17 14:22:19 +02:00
public function __construct(MediaPath $media)
{
$this->media = $media;
}
2021-09-09 19:18:41 +02:00
public function tmpPath(): string
{
return "/tmp/".str_slug(microtime());
}
2021-10-31 22:03:34 +01:00
protected function versionFilename($width, $height): string
2021-09-17 13:29:16 +02:00
{
2021-10-31 22:03:34 +01:00
return $this->media->filename().
2021-09-17 13:29:16 +02:00
'-'.
$width.
'x'.
$height.
'.'.$this->getExtension();
}
2021-09-17 13:31:44 +02:00
public function moveTo(string $source, string $destination): void
{
if (Storage::exists($destination)) {
Storage::delete($destination);
}
Storage::move($source, $destination);
}
2021-09-09 19:18:41 +02:00
}