For some unknown reason, when I upload a png with a transparent background via my script, the background turns black. If I manually upload the same png with a transparent background, it works perfectly. Any pointers appreciated.
public function update_site_logo_app_setting(){
$appSettingModel = model('\App\Models\AppSettingModel');
if ($this->request->getMethod() == "post") {
$validation = \Config\Services::validation();
$rules = [
"dh_site_logo" => [
"label" => "Site Logo",
"rules" =>
'uploaded[dh_site_logo]'
. '|is_image[dh_site_logo]'
. '|mime_in[dh_site_logo,image/jpg,image/jpeg,image/gif,image/png,image/webp]'
. '|max_size[dh_site_logo,200000]'
. '|max_dims[dh_site_logo,500,150]',
],
];
if ( $this->validate($rules) ){
$x_file = $this->request->getFile('dh_site_logo');
$x_file_name = $x_file->getName();
$image = \Config\Services::image()
->withFile($x_file)
->save(FCPATH . $x_file_name);
$data[] = array(
'app_setting_key' => 'dh_site_logo',
'app_setting_value' => $x_file_name,
);
$count = $appSettingModel->update_general_app_setting_batch( $data, 'app_setting_key');
if ($count > 0) {
$this->cache_delete();
return redirect()->to('/admin/settings')
->with('info', 'Success - settings updated!');
} else {
return redirect()->back()
->with('warning', 'Nothing to Update')
->withInput();
}
} else {
// return the validation errors.
return redirect()->back()
->with('errors', $validation->getErrors())
->with('warning', 'Invalid Data')
->withInput();
}
}
}
So basis the research I did, it seems I need to set the transparent color. How do I know what color PNG uses to set the transparent color? Is is always black? How do I say make the transparent color black?