oc-resizer-plugin/compressors/Compressor.php

49 lines
965 B
PHP
Raw 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;
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;
2021-09-17 13:29:16 +02:00
abstract protected function getExtension();
2021-09-17 17:09:17 +02:00
abstract public function getExtensionRegex(): string;
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
}