Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.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
Php TCPDF和base64图像_Php_Image_Tcpdf - Fatal编程技术网

Php TCPDF和base64图像

Php TCPDF和base64图像,php,image,tcpdf,Php,Image,Tcpdf,下午好, 我在使用TCPDF lib在PDF文档中插入图像时遇到问题。通过以下方式从JSignature捕获图像: $uri=base64_decode($_POST['firma']); $filename=SIGNATURE_IMAGE_PATH.ucfirst(strtolower(($_POST['cognome']))).ucfirst(strtolower(($_POST['nome'])))."-".$birthday.".png"; $ret=file_put_contents(

下午好, 我在使用TCPDF lib在PDF文档中插入图像时遇到问题。通过以下方式从JSignature捕获图像:

$uri=base64_decode($_POST['firma']);
$filename=SIGNATURE_IMAGE_PATH.ucfirst(strtolower(($_POST['cognome']))).ucfirst(strtolower(($_POST['nome'])))."-".$birthday.".png";
$ret=file_put_contents($filename, $uri);
<?php
    $string=base64_encode(file_get_contents(str_replace(" ", "", SIGNATURE_IMAGE_PATH.$member->firma)))
?>
<img src="data:image/svg+xml;base64,<?php echo $string ?>" />
在另一个PHP页面中,我可以通过以下方式正确查看图像:

$uri=base64_decode($_POST['firma']);
$filename=SIGNATURE_IMAGE_PATH.ucfirst(strtolower(($_POST['cognome']))).ucfirst(strtolower(($_POST['nome'])))."-".$birthday.".png";
$ret=file_put_contents($filename, $uri);
<?php
    $string=base64_encode(file_get_contents(str_replace(" ", "", SIGNATURE_IMAGE_PATH.$member->firma)))
?>
<img src="data:image/svg+xml;base64,<?php echo $string ?>" />
返回此错误:TCPDF错误:[Image]无法获取图像的大小:@***并将校正后的图像可视化

  • 这样:

    $string=file_get_contents(str_replace(" ", "", SIGNATURE_IMAGE_PATH.$member->firma));
    $pdf->Image('@'.$string);
    
    $string=file_get_contents(str_replace(" ", "", SIGNATURE_IMAGE_PATH.$member->firma));
    $img = '<img src=data:image/svg+xml;base64,'.$string.'>';
    $pdf->writeHTML($img, true, false, true, false, '');
    
    $string=file\u get\u contents(str\u replace(“,”,SIGNATURE\u IMAGE\u PATH.$member->firma));
    $img='';
    $pdf->writeHTML($img,true,false,true,false,”);
    
  • 不返回错误,但不显示图像。
    我已经阅读了关于这个问题的其他线程,但任何提出的解决方案似乎都不适合我。

    在我的项目中,我使用JSignature+TCPDF完美地解决了这个问题:

    符号:
    -HTML

    <div id="signature"></div><br>
    <input type="hidden" id="hiddenSigData" name="hiddenSigData" />
    
    TCPDF代码:

    $firmacode=$_POST['hiddenSigData'];
    $firmatradotta=base30_to_jpeg($firmacode,'nameofimage.png');
    $firmadefinitiva='path/to/image/'.$firmatradotta;
    $content='
    
    <table border="0">
        <tr>
            <td style="border-bottom:1pt solid black;"><img src="'.$firmadefinitiva.'"></td>
        </tr>
    
    </table>
    ';
    $obj_pdf->writeHTMLCell(120, 20, 80, 244, $content);
    
    function base30_to_jpeg($base30_string, $output_file) {
    require_once ('./jSignature/jSignature_Tools_Base30.php');
    $data = str_replace ( 'image/jsignature;base30,', '', $base30_string );
    $converter = new jSignature_Tools_Base30 ();
    $raw = $converter->Base64ToNative ( $data );
    // Calculate dimensions
    $width = 0;
    $height = 0;
    foreach ( $raw as $line ) {
        if (max ( $line ['x'] ) > $width)
            $width = max ( $line ['x'] );
        if (max ( $line ['y'] ) > $height)
            $height = max ( $line ['y'] );
    }
    
    // Create an image
    $im = imagecreatetruecolor ( $width + 20, $height + 20 );
    
    // Save transparency for PNG
    imagesavealpha ( $im, true );
    // Fill background with transparency
    $trans_colour = imagecolorallocatealpha ( $im, 255, 255, 255, 127 );
    imagefill ( $im, 0, 0, $trans_colour );
    // Set pen thickness
    imagesetthickness ( $im, 2 );
    // Set pen color to black
    $black = imagecolorallocate ( $im, 0, 0, 0 );
    // Loop through array pairs from each signature word
    for($i = 0; $i < count ( $raw ); $i ++) {
        // Loop through each pair in a word
        for($j = 0; $j < count ( $raw [$i] ['x'] ); $j ++) {
            // Make sure we are not on the last coordinate in the array
            if (! isset ( $raw [$i] ['x'] [$j] ))
                break;
            if (! isset ( $raw [$i] ['x'] [$j + 1] ))
                // Draw the dot for the coordinate
                imagesetpixel ( $im, $raw [$i] ['x'] [$j], $raw [$i] ['y'] [$j], $black );
            else
                // Draw the line for the coordinate pair
                imageline ( $im, $raw [$i] ['x'] [$j], $raw [$i] ['y'] [$j], $raw [$i] ['x'] [$j + 1], $raw [$i] ['y'] [$j + 1], $black );
        }
    }
    
    // Check if the image exists
    if (! file_exists ( dirname ( $output_file ) )) {
        mkdir(dirname($output_file));
    }
    
    // Create Image
    $ifp = fopen ( $output_file, "wb" );
    imagepng ( $im, $output_file );
    fclose ( $ifp );
    imagedestroy ( $im );
    copy($output_file, 'path/to/image/'.$output_file);
    unlink( $output_file );
    return $output_file;
    }
    
    $firmacode=$\u POST['hiddenSigData'];
    $firmatradotta=base30_to_jpeg($firmacode,'nameofimage.png');
    $firmadefinitiva='path/to/image/'。$firmatradotta;
    $content='1
    ';
    $obj_pdf->writeHTMLCell(120,20,80244,$content);
    
    解码图像的功能:

    $firmacode=$_POST['hiddenSigData'];
    $firmatradotta=base30_to_jpeg($firmacode,'nameofimage.png');
    $firmadefinitiva='path/to/image/'.$firmatradotta;
    $content='
    
    <table border="0">
        <tr>
            <td style="border-bottom:1pt solid black;"><img src="'.$firmadefinitiva.'"></td>
        </tr>
    
    </table>
    ';
    $obj_pdf->writeHTMLCell(120, 20, 80, 244, $content);
    
    function base30_to_jpeg($base30_string, $output_file) {
    require_once ('./jSignature/jSignature_Tools_Base30.php');
    $data = str_replace ( 'image/jsignature;base30,', '', $base30_string );
    $converter = new jSignature_Tools_Base30 ();
    $raw = $converter->Base64ToNative ( $data );
    // Calculate dimensions
    $width = 0;
    $height = 0;
    foreach ( $raw as $line ) {
        if (max ( $line ['x'] ) > $width)
            $width = max ( $line ['x'] );
        if (max ( $line ['y'] ) > $height)
            $height = max ( $line ['y'] );
    }
    
    // Create an image
    $im = imagecreatetruecolor ( $width + 20, $height + 20 );
    
    // Save transparency for PNG
    imagesavealpha ( $im, true );
    // Fill background with transparency
    $trans_colour = imagecolorallocatealpha ( $im, 255, 255, 255, 127 );
    imagefill ( $im, 0, 0, $trans_colour );
    // Set pen thickness
    imagesetthickness ( $im, 2 );
    // Set pen color to black
    $black = imagecolorallocate ( $im, 0, 0, 0 );
    // Loop through array pairs from each signature word
    for($i = 0; $i < count ( $raw ); $i ++) {
        // Loop through each pair in a word
        for($j = 0; $j < count ( $raw [$i] ['x'] ); $j ++) {
            // Make sure we are not on the last coordinate in the array
            if (! isset ( $raw [$i] ['x'] [$j] ))
                break;
            if (! isset ( $raw [$i] ['x'] [$j + 1] ))
                // Draw the dot for the coordinate
                imagesetpixel ( $im, $raw [$i] ['x'] [$j], $raw [$i] ['y'] [$j], $black );
            else
                // Draw the line for the coordinate pair
                imageline ( $im, $raw [$i] ['x'] [$j], $raw [$i] ['y'] [$j], $raw [$i] ['x'] [$j + 1], $raw [$i] ['y'] [$j + 1], $black );
        }
    }
    
    // Check if the image exists
    if (! file_exists ( dirname ( $output_file ) )) {
        mkdir(dirname($output_file));
    }
    
    // Create Image
    $ifp = fopen ( $output_file, "wb" );
    imagepng ( $im, $output_file );
    fclose ( $ifp );
    imagedestroy ( $im );
    copy($output_file, 'path/to/image/'.$output_file);
    unlink( $output_file );
    return $output_file;
    }
    
    函数base30到jpeg($base30字符串,$output文件){
    需要_once('./jSignature/jSignature_Tools_Base30.php');
    $data=str_replace('image/jsignature;base30',''.$base30_string);
    $converter=新的jSignature\u Tools\u Base30();
    $raw=$converter->Base64ToNative($data);
    //计算尺寸
    $width=0;
    $height=0;
    foreach(原始为$行){
    如果(最大($line['x'])>$width)
    $width=max($line['x']);
    如果(最大($line['y'])>$height)
    $height=max($line['y']);
    }
    //创建一个图像
    $im=ImageCreateTureColor($width+20,$height+20);
    //保存PNG的透明度
    imagesavealpha($im,true);
    //用透明度填充背景
    $trans_color=imagecoloralallocatealpha($im,255,255,255,127);
    imagefill($im,0,0,$trans_color);
    //设置笔厚
    imagesetthickness($im,2);
    //将钢笔颜色设置为黑色
    $black=imagecolorallocate($im,0,0,0);
    //循环遍历每个签名字的数组对
    对于($i=0;$i

    希望这能帮助你!再见;)

    你好,卢卡,你看到我的答案了吗?