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

。_饼干妹妹 提交于 2019-12-10 16:25:36

问题


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?


回答1:


$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);


来源:https://stackoverflow.com/questions/14926955/imagecreatefromstring-using-image-with-dataimage-pngbase64

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!