0

キャンバスから画像をキャプチャし、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.
?>  
4

1 に答える 1

1

$newIm='test.png';<br> if(exif_imagetype($newIm)==IMAGETYPE_PNG) {<br> $file_type="PNG";<br> }elseif (exif_imagetype($newIm) ==IMAGETYPE_JPEG) {<br> $file_type="JPG";<br> }<br> $pdf->Image($newIm,null,null,150,100,$file_type);<br>

Fpdfでは、画像シナタックスは画像全体をピクセルごとに読み取り、画像ベースがpngで拡張子をtest.jpgとして指定するとエラーが発生するため、ここではexif_imagetype()を使用して画像を取得します画像のタイプ。次に、この $file_type を構文に渡して結果を取得します。私の場合はうまくいきました。

于 2015-05-19T06:05:10.850 に答える