Pop\Image\Svg::__construct PHP Метод

__construct() публичный Метод

Instantiate an SVG image object based on either a pre-existing SVG image file on disk, or a new SVG image file.
public __construct ( string $svg, integer | string $w = null, integer | string $h = null, Pop\Color\Space\ColorInterface $color = null ) : Svg
$svg string
$w integer | string
$h integer | string
$color Pop\Color\Space\ColorInterface
Результат Svg
    public function __construct($svg, $w = null, $h = null, ColorInterface $color = null)
    {
        parent::__construct($svg);
        // If SVG image exists, get image info and store in an array.
        if (file_exists($this->fullpath) && $this->size > 0) {
            $this->resource = new \SimpleXMLElement($svg, null, true);
            $w = $this->resource->attributes()->width;
            $h = $this->resource->attributes()->height;
            // If SVG image does not exists, check to make sure the width and height
            // properties of the new SVG image have been passed.
        } else {
            if (null === $w || null === $h) {
                throw new Exception('Error: You must define a width and height for a new image object.');
            }
            $this->backgroundColor = null !== $color ? $color : new Rgb(255, 255, 255);
            $newSvg = "<?xml version=\"1.0\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<svg width=\"{$w}\" height=\"{$h}\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n    <desc>\n        SVG Image generated by Pop PHP Library\n    </desc>\n</svg>\n";
            $this->resource = new \SimpleXMLElement($newSvg);
            if (null !== $color) {
                $rect = $this->resource->addChild('rect');
                $rect->addAttribute('x', '0' . $this->units);
                $rect->addAttribute('y', '0' . $this->units);
                $rect->addAttribute('width', $w);
                $rect->addAttribute('height', $h);
                $rect->addAttribute('fill', $color->get(3, true));
            }
        }
        if (!is_numeric(substr($w, -1)) && !is_numeric(substr($w, -2, 1))) {
            $unit = substr($w, -2);
            if (in_array($unit, $this->allowedUnits)) {
                $this->units = $unit;
            }
            $this->width = (double) substr($w, 0, -2);
            $this->height = (double) substr($h, 0, -2);
        } else {
            if (!is_numeric(substr($w, 0, -1)) && substr($w, 0, -1) == '%') {
                $this->units = '%';
                $this->width = (double) substr($w, 0, -1);
                $this->height = (double) substr($h, 0, -1);
            } else {
                $this->width = (double) $w;
                $this->height = (double) $h;
            }
        }
    }