如何创建的base64 EN codeD JPEG GD图像? [英] How to create GD Image from base64 encoded jpeg?
本文介绍了如何创建的base64 EN codeD JPEG GD图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个上传API,作为一个响应对象提供(与其他东西一起JSON对象中)一个base64 EN codeD JPEG图像。
I have an upload Api that as a response object delivers (along with other stuff inside a Json object) a base64 encoded jpeg image.
我创建连接$ C $光盘镜像像这样:
I create the encoded image as so:
$im; // gd image resource
ob_start();
imagejpeg($im);
$data = base64_encode(ob_get_clean());
然后,数据被放在使用JavaScript在表单域内,并提交。
The data then is put inside a form field using javascript and submitted.
我怎么能再次创建一个GD资源,这样实际上,我可以说图像保存为一个文件?
How can I create a GD resource from that again so that I actually can save that image as a file?
在PHP中的一切。
推荐答案
您可以使用 imagecreatefromstring()功能:
$data = base64_decode($_POST['image_as_base64']);
$formImage = imagecreatefromstring($data);
字符串并不意味着真正的字符串。在这种情况下,它意味着字节/ BLOB数据。
"String" does not mean a "real" string. In that case it means bytes/blob data.
这篇关于如何创建的base64 EN codeD JPEG GD图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文