oc-resizer-plugin/compressors/Compressor.php

49 lines
983 B
PHP

<?php
namespace Aweos\Resizer\Compressors;
use Aweos\Resizer\Lib\MediaPath;
use Storage;
abstract class Compressor
{
protected $media;
abstract function make(string $path): array;
abstract protected function getExtension();
abstract public function getExtensionRegex(): string;
public function __construct(MediaPath $media)
{
$this->media = $media;
}
public function tmpPath(): string
{
return "/tmp/".str_slug(microtime());
}
protected function versionFilename(string $source, $width, $height): string
{
return pathinfo($source, PATHINFO_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);
}
}