Skip to content

Commit

Permalink
fix: image resize (work in progress) (#174)
Browse files Browse the repository at this point in the history
* fix: image resize (work in progress)

* style: formatting

* fix: scaleDown
  • Loading branch information
64knl authored Jan 2, 2024
1 parent 0848dee commit 708d90f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
16 changes: 8 additions & 8 deletions src/Services/Assets/Components/ComponentImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Intervention\Image\Drivers\Imagick\Driver;
use Intervention\Image\ImageManager;
use NotFound\Framework\Models\Menu;
use NotFound\Framework\Services\Assets\Enums\AssetType;
Expand Down Expand Up @@ -86,7 +87,9 @@ public function save()
$filename = $this->recordId.'_'.$dimensions->filename.'.jpg';

// create new image instance
$image = (new ImageManager(['driver' => 'imagick']))->make(new File(request()->file($fileId)->path()));
$image = (new ImageManager(
new Driver()
))->read(new File(request()->file($fileId)->path()));

if ($dimensions->height === '0') {
$height = intval($image->height() / $image->width() * $width);
Expand All @@ -96,18 +99,15 @@ public function save()
}

if (isset($dimensions->cropType) && $dimensions->cropType === 'fitWithin') {
$image->resize($width, $height, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
$image->scaleDown($width, $height);
} else {
$image->fit($width, $height);
$image->coverDown($width, $height);
}

$image->save(
$image->toJpeg()->save(
Storage::path('public').$this->relativePathToPublicDisk().$filename
);
$image->save(
$image->toWebp()->save(
Storage::path('public').$this->relativePathToPublicDisk().$filename.'.webp'
);
}
Expand Down
11 changes: 6 additions & 5 deletions src/Services/Assets/Components/ComponentText.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Http\File;
use Illuminate\Support\Facades\Storage;
use Intervention\Image\Drivers\Imagick\Driver;
use Intervention\Image\ImageManager;
use NotFound\Framework\Models\EditorSetting;
use NotFound\Framework\Models\FileUpload;
Expand Down Expand Up @@ -95,12 +96,12 @@ public function asyncPostRequest()
$width = 1200;

// create new image instance
$image = (new ImageManager(['driver' => 'imagick']))->make(new File(request()->file('file')));
$image->resize($width, null, function ($constraint) {
$constraint->aspectRatio();
});
$image = (new ImageManager(
new Driver()
))->read(new File(request()->file('file')));
$image->scaleDown($width, null);

$image->save(
$image->toJpeg()->save(
Storage::path('public').$folder.$filename
);

Expand Down

0 comments on commit 708d90f

Please sign in to comment.