I am currently doing the following to decode base64 images in PHP:
$img = str_replace('data:image/jpeg;base64,', '', $s['image']);
$img = str_replace('data:image/png;base64,', '', $s['image']);
$img = str_replace('data:image/gif;base64,', '', $s['image']);
$img = str_replace('data:image/bmp;base64,', '', $s['image']);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
As you can see above we are accepting the four most standard image types (jpeg, png, gif, bmp);
However, some of these images are very large and scanning through each one 4-5 times with str_replace seems a dreadful waste and terribly inefficient.
Is there a way I could reliably strip the data:image part of a base64 image string in a single pass? Perhaps by detecting the first comma in the string?
My apologies if this is a simple problem, PHP is not my forte. Thanks in advance.