我有一个以字符串形式存储的图像,它以以下内容开头:
data:image/png;base64,
我需要将它转换为普通图像以便在GD中使用。
我尝试使用imagecreatefromstring()
,但似乎只接受没有data:image/etc
前缀的图片。
我该怎么做?
$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);
data:type;base64,xxx
。只需查找第一个逗号即可。 - Marc B