PHPOffice / PHPWord

A pure PHP library for reading and writing word processing documents
https://phpoffice.github.io/PHPWord/
Other
7.28k stars 2.7k forks source link

I'm inserted an image using the addimage function without any error, but the image is not displayed #2682

Open gbnew opened 2 months ago

gbnew commented 2 months ago

Describe the bug and add attachments

i check the document ,images file is not in the word zip file.

Expected behavior

why the image is not in file,the path is correct.

Steps to reproduce

`foreach ($sceneCheckList as $item) { $table->addRow(); $table->addCell(200)->addText($row_total++); //$table->addCell(2000)->addText($item['picUrl']); // 第二列:插入图片 $picUrlAry=explode(',',$item['picUrl']);

                         //var_dump($picUrlAry);
                        if (count($picUrlAry)>0) {

                            $cell = $table->addCell(2000); // 创建一个较大的单元格
                            $cell->addText('隐患图片:'); // 添加文本标题
                            $cell->addBreak(); // 换行

                            foreach ($picUrlAry as $picUrl) {
                                if($picUrl){
                                    $imageStyle = array('width' => 100, 'height' => 100, 'wrappingStyle' => 'behind');
                                    //echo "<img src='../../".$picUrl."'>";
                                    $filePath = realpath($picUrl);
                                    if ($filePath !== false) {
                                        echo "文件的绝对路径是: $filePath";
                                    } else {
                                        echo "文件不存在或者路径有误";
                                    }

                                    $cell->addImage($picUrl, $imageStyle);                                  
                                    $cell->addBreak(); // 换行
                                }
                            }
                        } else {
                            $table->addCell(2000)->addText('无图片');
                        }`

PHPWord version(s) where the bug happened

3

PHP version(s) where the bug happened

7.4.3

Priority

gbnew commented 2 months ago

i try it again ,if i use section container the images can insert into document,but i use cell container the image only a blank without picture,the php had aready turn on the GD library.