I'm working with laravel 7 and using intervention/image to store images. However, I want to encode and store images as webp, I'm using the following code but it is not encoding the image in webp rather it is storing in the original format. Can you please tell me what I'm doing wrong?
public function storePoster(Request $request, Tournament $tournament)
{
if ($request->hasFile('poster')) {
$tournament->update([
'poster' => $request->poster->store('images', ['disk' => 'public_uploads']),
]);
$image = Image::make(public_path('uploads/' . $tournament->poster))->encode('webp', 90)->resize(200, 250);
$image->save();
}
}
encode
notsave
@CBroe – Slug$image = Image::make(public_path('uploads/' . $tournament->poster))->encode('webp', 90)->resize(200, 250)->save(public_path('/images/users/listing-images/' . 'Image'));
– Vocalic$image->save();
does that. The abstract “Image” object in memory might have the webp encoded version added to it (encode method description from docs, “Return value: Instance of Intervention\Image\Image with attached encoded image data.“), but if the file name sored internally ends with.jpg
, thensave
without additional parameters will still store it in that encoding. – Ing