我在浏览器截图中遇到了这个问题,其中生成的具有透明背景的Base64图像被截断:How do I resize an image without it getting cropped while maintaining aspect ratio in browsershot headerHtml?
因此,我想在用户上传时将图像的背景色从透明转换为白色,以防止此问题发生.然而,我没有找到任何关于这方面的现有资源,只有反过来.
如何在php/laravel中做到这一点?谢谢
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);
}