imagecreatefromstring using image with data:image/png;base64,

gd, php

Solution

$exploded = explode(',', $data, 2); // limit to 2 parts, i.e: find the first comma
$encoded = $exploded[1]; // pick up the 2nd part
$decoded = base64_decode($encoded);
$img_handler = imagecreatefromstring($decoded);

Problem

I've an image stored as string that starts with: ``` data:image/png;base64, ``` I need to convert it to a normal image for use it with GD. I tried `imagecreatefromstring()` but it seems to accept only images without the `data:image/etc` pefix. How can I do?

Original source