I'm going crazy and I need some help. I have a transparent image string in the variable $imageString, which I got by using file_get_contents('transparent_image.png'). However, as soon as I use the createimagefromstring() function the transparency is removed.
This works fine and keeps the transparency:
echo '<img src="data:image/png;base64,'.base64_encode($imageString).'">'; exit;
This removes the transparency and gives me a white background:
$image = imagecreatefromstring($imageString);
header("Content-Type: image/png");
imagepng($image);
exit;
Can someone please explain why this happens and how I keep the transparency after imagecreatefromstring()? I need to resize the transparent image but I'm stuck at the beginning.
I have even tried to "turn it around" by using the base64 method back into the png function but it didn't work, unfortunately;
$image = imagecreatefrompng('data:image/png;base64,'.base64_encode($imageString));
I've read all other questions regarding this topic but no one seems to have this problem with the basic function imagecreatefromstring() actually removing the transparency.
PHP: 7.4.11
GD: 2.2.5
Any ideas?