I would suggest you to refer link -
This could be possible an issue with metadata present in base64 string.
As per source the problem could be due to data:image/png;base64, is included in binary string.
The metadata present in the binary string results in invalid image data when the decoded back. Can you try it by removing metadata in the function before decoding the string.
You may use function and write output to a new file.
$position_s= strpos($base64_string , "data:image/png;base64,");
substr($base64_string, 0, $position_s) . substr($base64_string, $position_s+ strlen("data:image/png;base64,");
Note: If you are preferring explode function, it would be best to set limits:
explode(',',$base64_string,2)