This commit is contained in:
Javier Garcia 2018-05-23 18:48:28 +02:00
parent d54cc6efee
commit a228811a61
2 changed files with 38 additions and 36 deletions

View File

@ -20,9 +20,9 @@ namespace PhpOffice\PhpWord\Shared;
use PhpOffice\PhpWord\Element\AbstractContainer;
use PhpOffice\PhpWord\Element\Row;
use PhpOffice\PhpWord\Element\Table;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\SimpleType\Jc;
use PhpOffice\PhpWord\SimpleType\NumberFormat;
use PhpOffice\PhpWord\Settings;
/**
* Common Html functions
@ -305,7 +305,6 @@ class Html
*/
private static function parseTable($node, $element, &$styles)
{
$elementStyles = self::parseInlineStyle($node, $styles['table']);
$newElement = $element->addTable($elementStyles);
@ -656,20 +655,20 @@ class Html
break;
}
}
if( strpos( $src, "data:image" ) !== false ){
if( ! is_dir( self::$imgdir ) )
if (strpos($src, 'data:image') !== false) {
if (!is_dir(self::$imgdir)) {
mkdir(self::$imgdir);
}
$match = array();
preg_match('/data:image\/(\w+);base64,(.+)/', $src, $match);
$src = $imgFile = self::$imgdir . uniqid() . "." . $match[1];
$src = $imgFile = self::$imgdir . uniqid() . '.' . $match[1];
$ifp = fopen( $imgFile, "wb");
$ifp = fopen($imgFile, 'wb');
fwrite($ifp, base64_decode($match[2]));
fclose($ifp);
}
$src = urldecode($src);
@ -683,13 +682,14 @@ class Html
if (!is_file($src)) {
if ($imgBlob = file_get_contents($src)) {
$tmpDir = Settings::getTempDir() . '/';
if( ! is_dir( $tmpDir ) )
if (!is_dir($tmpDir)) {
mkdir($tmpDir);
}
$match = array();
preg_match('/.+\.(\w+)$/', $src, $match);
$src = $tmpDir . uniqid() . "." . $match[1];
$src = $tmpDir . uniqid() . '.' . $match[1];
$ifp = fopen( $src, "wb");
$ifp = fopen($src, 'wb');
fwrite($ifp, $imgBlob);
fclose($ifp);

View File

@ -115,6 +115,7 @@ class HtmlTest extends \PHPUnit\Framework\TestCase
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:rPr/w:u'));
$this->assertEquals('single', $doc->getElementAttribute('/w:document/w:body/w:p/w:r/w:rPr/w:u', 'w:val'));
}
/**
* Test font
*/
@ -478,6 +479,7 @@ class HtmlTest extends \PHPUnit\Framework\TestCase
$baseXpath = '/w:document/w:body/w:p/w:r';
$this->assertTrue($doc->elementExists($baseXpath . '/w:pict/v:shape'));
}
/**
* Test parsing of remote img that can be found locally
*/
@ -487,7 +489,7 @@ class HtmlTest extends \PHPUnit\Framework\TestCase
$localPath = __DIR__ . '/../_files/images/';
$options = array(
'IMG_SRC_SEARCH' => 'https://fakedomain.io/images/',
'IMG_SRC_REPLACE'=> $localPath
'IMG_SRC_REPLACE' => $localPath,
);
$phpWord = new \PhpOffice\PhpWord\PhpWord();