Browse code

Initial commit

Benjamin Roth authored on26/02/2024 17:53:24
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,30 @@
1
+<?php
2
+
3
+
4
+namespace vonRotenberg\RealEstateListingBundle\Twig;
5
+
6
+use Twig\Extension\AbstractExtension;
7
+use Twig\TwigFilter;
8
+
9
+class AppExtension extends AbstractExtension
10
+{
11
+  public function getFilters(): array
12
+  {
13
+    return [
14
+      new TwigFilter('mm2pt', [$this, 'convertMillimeterToPoint']),
15
+      new TwigFilter('imageDataUrl', [$this, 'getImageDataUrl']),
16
+    ];
17
+  }
18
+
19
+  public function convertMillimeterToPoint(float $mm): float
20
+  {
21
+    return (float) $mm / 25.4 * 72;
22
+  }
23
+
24
+  public function getImageDataUrl(string $path): string
25
+  {
26
+    $type = pathinfo($path, PATHINFO_EXTENSION);
27
+    $data = file_get_contents($path);
28
+    return 'data:image/' . $type . ';base64,' . base64_encode($data);
29
+  }
30
+}