Giter Site home page Giter Site logo

How to output and save about php-svg HOT 2 CLOSED

meyfa avatar meyfa commented on May 18, 2024
How to output and save

from php-svg.

Comments (2)

meyfa avatar meyfa commented on May 18, 2024

I'm assuming you've already got an SVG object (an image) loaded from somewhere or constructed one manually.

You can use its toXMLString() method to obtain the SVG in text form, and then write that out whichever way you prefer. The simplest way would be using PHP's file_put_contents.

Complete example:

<?php
require __DIR__ . '/vendor/autoload.php';

use SVG\SVG;
use SVG\Nodes\Shapes\SVGRect;

// image with 100x100 viewport
$image = new SVG(100, 100);
$doc = $image->getDocument();

// blue 40x40 square at (0, 0)
$square = new SVGRect(0, 0, 40, 40);
$square->setStyle('fill', '#0000FF');
$doc->addChild($square);

// obtain the SVG text
$svgString = $image->toXMLString();

// write it to a file
file_put_contents('path/to/the-file.svg', $svgString);

I hope this solved your problem. Please, always ask if something is unclear!

from php-svg.

meyfa avatar meyfa commented on May 18, 2024

I'm closing this issue under the assumption that it has been solved. Please reopen it if I'm wrong.

from php-svg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.