Я захватил изображение с холста и отправил его с помощью метода post ajax в мой php-файл.PHP dataURL to png image
Здесь мне нужно вернуть его в png с типом файла и расширением. Поскольку я добавлю это новое изображение в pdf, используя fpdf.
Вот мой код. Я просто остался со сломанным значком ссылки на изображение.
<?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.
?>
'explode (',', $ imgEmbed);' должно быть 'explode ('.', $ ImgEmbed);'? Выводит ли вывод в качестве изображения? Я сомневаюсь. Изменить 'header ('Content-Type: image/png');' to 'header ('Content-Type: application/pdf');' –
Результат - это FPDF. он не влияет на создание изображения. Мне нужно fpdf распознать datauri как изображение png, следовательно, заголовок. к сожалению, ваше предложение еще раз нарушает код ... :( – user61026
Можете ли вы сохранить PNG во временное расположение на сервере, прежде чем записывать его в PDF? –