oc-resizer-plugin/compressors/Compressor.php

47 lines
924 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-09-17 14:22:19 +02:00
protected $media;
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 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-09-17 13:29:16 +02:00
protected function versionFilename(string $source, $width, $height): string
{
return pathinfo($source, PATHINFO_FILENAME).
'-'.
$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
}