How to make the signature be saved on the server in a png file?

How to make the signature be saved on the server in a png file, I want to make the signature save in a png file, I need it as a photo because I’m using it to create a contract.

I tried gptchat help but unfortunately it doesn’t work well. And that is my “saveing code” but doesn’t work properly, when I try to open a photo I get the message “the format is currently not supported or the file is corrupted”

$folderPath = "C:/xampp/htdocs/podpis/";
    $image_parts = explode(";base64,", $podpis); 
    $image_type_aux = explode("image/", $image_parts[0]);
    $file = $folderPath .'signature_'.$imie_nazwisko.'_'.$data1.'.png';
    $image = imagecreatefromstring(base64_decode($image_parts[0]));
imagepng($image, $file);
imagedestroy($image);