Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

gd

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?

like image 262
Fez Vrasta Avatar asked Feb 17 '13 22:02

Fez Vrasta


1 Answers

$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);
like image 160
arhak Avatar answered Oct 16 '22 07:10

arhak