Skip to content
This repository has been archived by the owner on Jun 4, 2022. It is now read-only.

Commit

Permalink
update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
bayareawebpro committed Apr 29, 2020
1 parent 679e00a commit cbc034b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 58 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ composer require bayareawebpro/nova-field-ckeditor
php artisan vendor:publish --tag=config
```

#### Install Optimizers

> See: https://github.com/spatie/image-optimizer
### Publish Stubs: Models, Resources, Migrations, Views

> Review the included stubs to see the intended implementation.
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"require": {
"php": ">=7.4",
"intervention/image": "^2.5",
"spatie/image-optimizer": "^1.2"
"laravel/framework": "^7.0",
"spatie/laravel-image-optimizer": "^1.6"
},
"autoload": {
"psr-4": {
Expand Down
20 changes: 11 additions & 9 deletions config/nova-ckeditor.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
<?php
return [
/**
* Intervention Image Max Dimensions
* @docs http://image.intervention.io/
* Max Memory (php.ini override) for Intervention Image Resizing
* @docs https://www.php.net/manual/en/ini.core.php#ini.memory-limit
*/
'max_width' => 1024,
'max_height' => 768,
'memory' => '256M',

/**
* Max Memory (php.ini override) for Image Resizing
* Max Intervention Image Output Quality
* before Image Optimizer is run.
* @docs http://image.intervention.io/api/save
*/
'memory' => '256M',
'max_quality' => 75,

/**
* Spatie Image Optimizer Bin Path
* @docs https://github.com/spatie/image-optimizer
* Intervention Image Max Dimensions
* @docs http://image.intervention.io/api/resize
*/
'bin_path' => '/usr/local/bin',
'max_width' => 1024,
'max_height' => 768,
];
53 changes: 5 additions & 48 deletions src/MediaStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@

namespace BayAreaWebPro\NovaFieldCkEditor;

use Illuminate\Support\Facades\DB;
use Throwable;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;

use Spatie\ImageOptimizer\OptimizerChain;
use Spatie\ImageOptimizer\Optimizers\Optipng;
use Spatie\ImageOptimizer\Optimizers\Pngquant;
use Spatie\ImageOptimizer\Optimizers\Gifsicle;
use Spatie\ImageOptimizer\Optimizers\Jpegoptim;

use Intervention\Image\Constraint;
use Intervention\Image\Facades\Image;
use Throwable;
use Spatie\LaravelImageOptimizer\Facades\ImageOptimizer;

class MediaStorage
{
Expand Down Expand Up @@ -104,7 +98,8 @@ protected function resize(UploadedFile $file): array
$constraint->upsize();
});
}
$image->save($file->getRealPath(), 75);

$image->save($file->getRealPath(), config('nova-ckeditor.max_quality', 75));

return [
'hash' => $hash,
Expand All @@ -124,45 +119,7 @@ protected function resize(UploadedFile $file): array
*/
public function optimize(string $tempPath):int
{
$binaryPath = config('nova-ckeditor.bin_path', '/usr/local/bin');

$optimizerChain = (new OptimizerChain())
->addOptimizer(
with(new Jpegoptim([
'--max75',
'--strip-all',
'--all-progressive',
'--quiet',
]))
->setBinaryPath($binaryPath)
)
->addOptimizer(
with(new Optipng([
'-i0',
'-o3',
'-quiet',
]))
->setBinaryPath($binaryPath)
)
->addOptimizer(
with(new Pngquant([
'--force',
'--skip-if-larger',
'--quality=75',
]))
->setBinaryPath($binaryPath)
)
->addOptimizer(
with(new Gifsicle([
'-b',
'-O3',
]))
->setBinaryPath($binaryPath)
);

$optimizerChain->useLogger(app('log'));
$optimizerChain->optimize($tempPath, $tempPath);

ImageOptimizer::optimize($tempPath);
return filesize($tempPath);
}

Expand Down

0 comments on commit cbc034b

Please sign in to comment.