> */ public static function allowed_svg_tags() { return array( 'svg' => array( 'xmlns' => true, 'xmlns:xlink' => true, 'version' => true, 'width' => true, 'height' => true, 'viewbox' => true, ), 'defs' => array(), 'lineargradient' => array( 'id' => true, 'gradientunits' => true, 'x1' => true, 'y1' => true, 'x2' => true, 'y2' => true, ), 'radialgradient' => array( 'id' => true, 'gradientunits' => true, 'cx' => true, 'cy' => true, 'r' => true, ), 'stop' => array( 'offset' => true, 'stop-color' => true, 'stop-opacity' => true, ), 'g' => array( 'fill' => true, 'fill-opacity' => true, 'transform' => true, ), 'rect' => array( 'x' => true, 'y' => true, 'width' => true, 'height' => true, 'fill' => true, 'fill-opacity' => true, ), 'path' => array( 'd' => true, 'fill' => true, 'fill-opacity' => true, 'fill-rule' => true, 'transform' => true, ), ); } /** * Render the given text as an inline SVG QR code. * * @param string $text Text to encode (e.g. a payment address). * @param int $size Pixel size of the square QR code. * @return string Inline SVG markup, or '' when unavailable / on error. */ public static function svg( $text, $size = 180 ) { if ( ! self::is_available() || '' === (string) $text ) { return ''; } try { $renderer = new ImageRenderer( new RendererStyle( (int) $size, 1 ), new SvgImageBackEnd() ); $writer = new Writer( $renderer ); $svg = $writer->writeString( (string) $text ); // Strip any leading XML prolog so the SVG can be embedded inline in // HTML without an invalid processing instruction. $svg = preg_replace( '/^\s*<\?xml[^>]*\?>\s*/i', '', $svg ); return $svg; } catch ( \Throwable $e ) { return ''; } } }