-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update Html.php Add position attr for image whitch driving by MemoryDrawing * add unit test for pr#3535 * Fix code styles * Fix code styles * use a local image instead of web image * add image for pr#3535 * code style fix
- Loading branch information
Showing
3 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
tests/PhpSpreadsheetTests/Writer/Html/MemoryDrawingOffsetTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace PhpOffice\PhpSpreadsheetTests\Writer\Html; | ||
|
||
use PhpOffice\PhpSpreadsheet\Spreadsheet; | ||
use PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing; | ||
use PhpOffice\PhpSpreadsheet\Writer\Html; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class MemoryDrawingOffsetTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider dataProvider | ||
*/ | ||
public function testMemoryDrawingOffset(int $w, int $h, int $x, int $y): void | ||
{ | ||
$spreadsheet = new Spreadsheet(); | ||
$sheet = $spreadsheet->getActiveSheet(); | ||
|
||
$image = file_get_contents(__DIR__ . '/../../../data/Reader/HTML/memoryDrawingTest.jpg'); | ||
self::assertNotFalse($image, 'unable to read file'); | ||
$image = imagecreatefromstring($image); | ||
self::assertNotFalse($image, 'unable to create image from string'); | ||
$drawing = new MemoryDrawing(); | ||
$drawing->setImageResource($image) | ||
->setResizeProportional(false) //是否保持比例 | ||
->setWidthAndHeight($w, $h) //图片宽高,原始尺寸 100*100 | ||
->setOffsetX($x) | ||
->setOffsetY($y) | ||
->setWorksheet($sheet); | ||
|
||
$writer = new Html($spreadsheet); | ||
$html = $writer->generateHtmlAll(); | ||
self::assertStringContainsString('width:' . $w . 'px;left: ' . $x . 'px; top: ' . $y . 'px;position: absolute;', $html); | ||
$spreadsheet->disconnectWorksheets(); | ||
unset($spreadsheet); | ||
} | ||
|
||
public function dataProvider(): array | ||
{ | ||
return [ | ||
[33, 19, 0, 20], | ||
[129, 110, 12, -3], | ||
[55, 110, 33, 42], | ||
]; | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.