19 declare(strict_types=1);
44 $pattern = new \Imagick();
46 $pattern->readImageBlob(
47 '<?xml version="1.0" encoding="UTF-8"?><svg id="Ebene_2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ' 48 . ($x * 2) .
' ' . ($x * 2) .
'"><defs><style>.cls-1{fill:#afafaf;}.cls-1,.cls-2{stroke-width:0px;}.cls-2{fill:#e8e8e8;}</style></defs><g id="Ebene_1-2"><rect class="cls-1" width="' 49 . $x .
'" height="' . $x .
'"/><rect class="cls-2" y="' . $x .
'" width="' . $x .
'" height="' . $x
50 .
'"/><rect class="cls-1" x="' . $x .
'" y="' . $x .
'" width="' . $x .
'" height="' . $x
51 .
'"/><rect class="cls-2" x="' . $x .
'" width="' . $x .
'" height="' . $x .
'"/></g></svg>' 53 $pattern = $img->textureImage($pattern);
54 $pattern->compositeImage(
56 \Imagick::COMPOSITE_OVER,
68 return new \ImagickPixel(
'none');
73 return \Imagick::ALPHACHANNEL_ACTIVATE;
78 return new \ImagickPixel(
'transparent');
88 return $this->pattern ?
'jpg' :
'png64';
96 private function prescaleSVG(
string $svg_content,
int $max_length): string
99 $dom = new \DOMDocument();
100 $dom->loadXML($svg_content);
101 $svg = $dom->documentElement;
104 $viewbox = $svg->getAttribute(
'viewBox');
105 if ($viewbox ===
'') {
108 $viewbox = explode(
' ', $viewbox);
109 $width = (float) ($viewbox[2] ?? 0);
110 $height = (float) ($viewbox[3] ?? 0);
112 if ($width === 0 || $height === 0) {
116 [$new_width, $new_height] = $this->calculateWidthHeight(
121 $svg->setAttribute(
'width', (
string) $new_width);
122 $svg->setAttribute(
'height', (
string) $new_height);
124 return $dom->saveXML($svg);