Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
到png图像的PHP数据URL_Php_Fpdf_Data Uri_Todataurl - Fatal编程技术网

到png图像的PHP数据URL

到png图像的PHP数据URL,php,fpdf,data-uri,todataurl,Php,Fpdf,Data Uri,Todataurl,我从画布上捕获了一个图像,并通过ajax post方法将其发送到我的php文件中 在这里,我需要把它放回一个带有文件类型和扩展名的png。因为我将使用fpdf将这个新图像添加到pdf中 这是我的密码。我只剩下一个断开的图像链接图标 <?php require_once('fpdf/fpdf.php'); require_once('fpdi/fpdi.php'); $imgEmbed = $_POST['embed']; //convert base64 string into an

我从画布上捕获了一个图像,并通过ajax post方法将其发送到我的php文件中

在这里,我需要把它放回一个带有文件类型和扩展名的png。因为我将使用fpdf将这个新图像添加到pdf中

这是我的密码。我只剩下一个断开的图像链接图标

<?php 
require_once('fpdf/fpdf.php');
require_once('fpdi/fpdi.php');
$imgEmbed = $_POST['embed'];

//convert base64 string into an image file by wrapping
//it in the png container

$parts = explode(',',$imgEmbed);
$data = $parts[1];
$data = base64_decode($data);

header('Content-Type:image/png');

$pdf =& new FPDI();
$pdf->AddPage();

//Set the source PDF file
$pdf->setSourceFile("test2.pdf");

//Import the first page of the file
$tppl = $pdf->importPage(1);

//Use this page as template
// use the imported page and place it at point 20,30 with a width of 170 mm
$pdf->useTemplate($tppl, null, null, 215.9, 279.4, TRUE);

//Select Arial italic 8
$pdf->SetFont('Helvetica');
$pdf->SetTextColor(0,0,0);
$pdf->SetXY(100, 100);
$pdf->Write(0, 'This is just a simple text');
$pdf->Image($newIm,null,null,150,100);// x y h w 'png'

$pdf->Output("custom.pdf", "I"); // d send to browser, F send to local
// I auto open in browser window.
?>  


$newIm='test.png'
如果(exif_imagetype($newIm)=imagetype_PNG){
$file_type=“PNG”
}elseif(exif_imagetype($newIm)=imagetype_JPEG){
$file_type=“JPG”
}
$pdf->Image($newIm,null,null,150100,$file\u type)


在Fpdf中,图像synatax逐像素读取整个图像,如果图像基为png,我们将扩展名设为test.jpg,那么它将给出一个错误,因此我在这里使用了exif_imagetype()这将给我图像的图像类型。然后我将在语法中传递这个$file\u类型以获得结果。在我的例子中,它已经起作用了。

explode(',',$imgEmbed)应该是
分解('.',$imgEmbed)
输出是否作为图像渲染?我怀疑。更改
标题('Content-Type:image/png')
标题('Content-Type:application/pdf')输出是FPDF的一部分。它对制作图像没有影响。我需要fpdf将datauri识别为png图像,从而识别标题。不幸的是,你的建议更违反了规则…:(在将PNG写入PDF之前,能否将其保存到服务器上的临时位置?可能的副本