oc-resizer-plugin/compressors/Compressor.php

39 lines
774 B
PHP
Raw Normal View History

2021-09-09 19:18:41 +02:00
<?php
namespace Aweos\Resizer\Compressors;
2021-09-17 13:31:44 +02:00
use Storage;
2021-09-09 19:18:41 +02:00
abstract class Compressor
{
abstract function make(string $path): array;
2021-09-17 13:29:16 +02:00
abstract protected function getExtension();
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
}