1

我尝试转换使用生成的数据 URI

canvas.Canvas.toDataURL();

我只是想使用以下代码将数据 URI 存储为图像

<?php $data = $_POST['image_designed'];
echo $data; //Data URI
echo '<img src="'.$data.'"/>'; //Getting the image perfectly
//removing the "data:image/png;base64," part
$uri =  substr($data,strpos($data,",")+1);

header('Content-type: image/png');
echo base64_decode($uri);exit; //Just image place holder displaying instead of full image

我得到以下数据

$data = data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPoAAAEsCAYAAADq/K67AAAgAElEQVR4Xky9WY8l6Xnn90acPffMqspauqqrit3sZrO5z2g0FATJIw0G8L0/gr
//Very longer data than this which cannot be pasted here

最终的图像结果是错误的。仅显示错误图像占位符。我猜原因是“我在 $data 中间发现了很长的空间”。但它在 src 标签中很好地呈现了图像。

4

0 回答 0