When presenting version 3, the Image Intervention package has seen many changes. codes version 2 in version 3 Not compatible and It needs to be changed.
okey.
Install Package Image Intervention :
in Database users, create table image :
Creating Field image :
<label for=”input8″ class=”form-label”>Upload image</label>
<input type=”file” name=”image” class=”form-control rounded-5 @error(‘image’) is-invalid @enderror” id=”input8″>
@error(‘image’)
<span class=”invalid-feedback” role=”alert”>
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
in windows xampp extension=imagick.so enable. in linux Enter the following commands :
php -m | grep imagick
sudo systemctl restart apache2
Creating Function saveImage in User.php :
public static function saveImage($file)
{
if ($file){
$name = $file->hashName();
$smallImage = ImageManager::imagick()->read($file->getRealPath());
$bigImage = ImageManager::imagick()->read($file->getRealPath());
$smallImage->resize(256, 256, function ($constraint){
$constraint->aspectRatio();
});
Storage::disk(‘local’)->put(‘users/small/’.$name, (string) $smallImage->encodeByMediaType(‘image/jpeg’, 90));
Storage::disk(‘local’)->put(‘users/big/’.$name, (string) $bigImage->encodeByMediaType(‘image/jpeg’, 90));
return $name;
}else{
return “”;
}
}
Function Store in UserController.php :
{
$image = User::saveImage($request->image);
User::query()->create([
‘name’ => $request->name,
’email’ => $request->email,
‘password’ => bcrypt($request->password),
‘image’ => $image,
]);
return to_route(‘users.index’);
}
in config/filesystem.php Enter the following codes :
[
‘driver’ => ‘local’,
‘root’ => public_path(‘images’),
‘throw’ => false,
],
Show Image User :
<figure>
<img src=”{{asset(‘images/users/small/’ .$row->image)}}” class=”rounded-4″ width=”52px”>
</figure>
@endforeach
Good luck. 🙂