8000 Add documetation of exporting remote image (#212) · anthony-dee/laravel-excel-docs@96aee52 · GitHub < 8000 link rel="manifest" href="/manifest.json" crossOrigin="use-credentials">
[go: up one dir, main page]

Skip to content

Commit 96aee52

Browse files
authored
Add documetation of exporting remote image (SpartnerNL#212)
* Add documetation of exporting remote image * improve readability
1 parent d1c9c19 commit 96aee52

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

3.1/exports/drawings.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,35 @@ class InvoicesExport implements WithDrawings
7676
return [$drawing, $drawing2];
7777
}
7878
}
79+
```
80+
81+
## Adding a drawing of remote image
82+
You can instantiate a new drawing from `\PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing`, and create a string containing the binary image data, or from an external url by `imagecreatefromstring(file_get_contents($url))`, then assign it to `setImageResource`. Return the Drawing instance in the `drawings` method.
83+
84+
```php
85+
<?php
86+
87+
namespace App\Exports;
88+
89+
use Maatwebsite\Excel\Concerns\WithDrawings;
90+
use PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing;
91+
92+
class InvoicesExport implements WithDrawings
93+
{
94+
public function drawings()
95+
{
96+
if (!$imageResource = @imagecreatefromstring(file_get_contents('http://example.jpg'))) {
97+
throw new \Exception('The image URL cannot be converted into an image resource.');
98+
}
99+
100+
$drawing = new MemoryDrawing();
101+
$drawing->setName('Logo');
102+
$drawing->setDescription('This is my logo');
103+
$drawing->setImageResource($imageResource);
104+
$drawing->setHeight(90);
105+
$drawing->setCoordinates('B3');
106+
107+
return $drawing;
108+
}
109+
}
79110
```

0 commit comments

Comments
 (0)
0