seed = $seed; } public function asDataURL() { $svg = $this->build(); return "data:image/svg+xml," . rawurlencode($svg); } public function build() { $this->createPatterns(); return $this->createSVG(); } abstract protected function createPatterns(); protected function createSVG() { $bg = $this->toSVGColor($this->backgroundColor); $stroke = $this->size * 0.005; $svg = ""; if ($this->singleColor) { $fg = $this->toSVGColor($this->getForegroundColor()); $svg .= ""; } else { $svg .= ""; } foreach ($this->rectangles as $rectangle) { $x = $rectangle["x"]; $y = $rectangle["y"]; $w = $rectangle["w"]; $h = $rectangle["h"]; if ($rectangle["color"] == $this->backgroundColor) { continue; } if ($this->singleColor) { $svg .= "\n"; } else { $color = $this->toSVGColor($rectangle["color"]); $svg .= "\n"; } } $svg .= ""; return $svg; } protected static function toSVGColor(array $color) { list($h, $s, $l) = $color; $h *= 360; $s *= 100; $l *= 100; $h=round($h); $s=round($s); $l=round($l); return "hsl($h, $s%, $l%)"; } abstract protected function getForegroundColor(); public function print() { header('Content-type:image/svg+xml;charset=utf-8'); echo $this->build(); } }