When I want to upload a JPG image to my Laravel ecommerce website this error occured:
Call to undefined function Intervention\Image\Drivers\Gd\Decoders\imagecreatefromjpeg()
But when I uploaded a PNG image it’s fine. How can I solve this issue?
This is my code:
$current_timestamp = Carbon::now()->timestamp;
if($request->hasFile('image'))
{
$image = $request->file('image');
$imageName = $current_timestamp.'.'.$image->extension();
$this->GenerateProductThumbnailImage($image,$imageName);
$product->image = $imageName;
}
$gallery_arr = array();
$gallery_images = "";
$counter = 1;
if($request->hasFile('images'))
{
$allowedfileExtension=['jpg','png','jpeg'];
$files = $request->file('images');
foreach($files as $file){
$gextension = $file->getClientOriginalExtension();
$check=in_array($gextension,$allowedfileExtension);
if($check)
{
$gfilename = $current_timestamp . "-" . $counter . "." . $gextension;
$this->GenerateProductThumbnailImage($file,$gfilename);
array_push($gallery_arr,$gfilename);
$counter = $counter + 1;
}
}
$gallery_images = implode(',', $gallery_arr);
}
$product->images = $gallery_images;
$product->category_id = $request->category_id;
$product->brand_id = $request->brand_id;
$product->save();
return redirect()->route('admin.products')->with('status','Product has been added successfully !');
}