I have this problem with browsershot wherein generated base64 image with transparent background is being truncated: How do I resize an image without it getting cropped while maintaining aspect ratio in browsershot headerHtml?
Hence, I wanted to convert the image's background color from transparent to white on user upload to prevent this issue from occurring. However, I don't find any existing resources on this, only the other way around.
How to do it in php/laravel? thank you
public function updatePdoImage($request, $id)
{
if (!$request->file('profile_image')) {
return;
}
$request->validate([
'profile_image' => 'required|image|mimes:jpeg,png,jpg,gif|max:2048'
]);
$file = $request->file('profile_image');
$image_properties = $this->uploadImage($file, 'uploads/');
$data = [
'file_name' => $image_properties[0],
'file_dir' => $image_properties[1],
'file_type' => $image_properties[2],
'file_size' => $image_properties[3]
];
$pdo = $this->show($id);
// Convert the image to Base64
$base64Image = base64_encode(file_get_contents($data['file_dir']));
$data['grant_proposal_logo'] = $base64Image;
// saving data in DB
$this->savingUploadImage($pdo, $data);
}