This commit is contained in:
philipp lang 2022-09-10 19:58:54 +02:00
parent 72597436a7
commit fe3a0625a1
2 changed files with 5 additions and 11 deletions

View File

@ -2,13 +2,12 @@
namespace Aweos\Resizer\Compressors; namespace Aweos\Resizer\Compressors;
use Aweos\Resizer\Exceptions\ResizerException;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Intervention\Image\ImageManager; use Intervention\Image\ImageManager;
use Storage; use Storage;
class JpgCompressor extends Compressor { class JpgCompressor extends Compressor
{
public function getExtensionRegex(): string public function getExtensionRegex(): string
{ {
return 'jpg'; return 'jpg';
@ -24,7 +23,7 @@ class JpgCompressor extends Compressor {
$output = $this->tmpPath(); $output = $this->tmpPath();
system('imagemin '.escapeshellarg($path).' --plugin=jpegtran --plugin=mozjpeg --plugin.mozjpeg.quality=70 > '.escapeshellarg($output)); system('imagemin '.escapeshellarg($path).' --plugin=jpegtran --plugin=mozjpeg --plugin.mozjpeg.quality=70 > '.escapeshellarg($output));
system("mv ".escapeshellarg($output)." ".escapeshellarg($path)); system('mv '.escapeshellarg($output).' '.escapeshellarg($path));
return [ return [
$path => [$path], $path => [$path],
@ -64,12 +63,9 @@ class JpgCompressor extends Compressor {
public function start(): void public function start(): void
{ {
//
} }
public function end(): void public function end(): void
{ {
//
} }
} }

View File

@ -9,7 +9,6 @@ use Storage;
class PdfCompressor extends Compressor class PdfCompressor extends Compressor
{ {
private string $originalImage; private string $originalImage;
public function getExtensionRegex(): string public function getExtensionRegex(): string
@ -28,7 +27,7 @@ class PdfCompressor extends Compressor
$mimetype = mime_content_type($path); $mimetype = mime_content_type($path);
system('imagemin '.escapeshellarg($path).' --plugin=jpegtran --plugin=mozjpeg --plugin.mozjpeg.quality=70 > '.escapeshellarg($output)); system('imagemin '.escapeshellarg($path).' --plugin=jpegtran --plugin=mozjpeg --plugin.mozjpeg.quality=70 > '.escapeshellarg($output));
system("mv ".escapeshellarg($output)." ".escapeshellarg($path)); system('mv '.escapeshellarg($output).' '.escapeshellarg($path));
return [ return [
$path => [$path], $path => [$path],
@ -78,7 +77,7 @@ class PdfCompressor extends Compressor
public function resize(Collection $size, bool $update, callable $callback): void public function resize(Collection $size, bool $update, callable $callback): void
{ {
$tempBefore = PATHINFO($this->originalImage, PATHINFO_FILENAME).'compiled.'.pathinfo($this->originalImage, PATHINFO_EXTENSION); $tempBefore = pathinfo($this->originalImage, PATHINFO_FILENAME).'compiled.'.pathinfo($this->originalImage, PATHINFO_EXTENSION);
$r = app(ImageManager::class)->make($this->originalImage) $r = app(ImageManager::class)->make($this->originalImage)
->fit($size->get('width'), $size->get('height')) ->fit($size->get('width'), $size->get('height'))
@ -91,5 +90,4 @@ class PdfCompressor extends Compressor
unlink($tempBefore); unlink($tempBefore);
call_user_func($callback, $this->media, Storage::path($versionFilename)); call_user_func($callback, $this->media, Storage::path($versionFilename));
} }
} }