imagecreatefromstring使用带数据的图像data:image/png; base64, [英] imagecreatefromstring using image with data:image/png;base64,

查看:243
本文介绍了imagecreatefromstring使用带数据的图像data:image/png; base64,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将图像存储为以以下字符串开头的字符串:

I've an image stored as string that starts with:

data:image/png;base64,

我需要将其转换为普通图像以用于GD.

I need to convert it to a normal image for use it with GD.

我尝试了imagecreatefromstring(),但是它似乎只接受没有data:image/etc pefix的图像.

I tried imagecreatefromstring() but it seems to accept only images without the data:image/etc pefix.

我该怎么办?

推荐答案

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

这篇关于imagecreatefromstring使用带数据的图像data:image/png; base64,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆