GithubHelp home page GithubHelp logo

Comments (5)

stelgenhof avatar stelgenhof commented on August 30, 2024

Yes, you can use the toRasterImage method to achieve that. See the README.md (Rasterizing section) for an example.

from php-svg.

ashickur-rahman avatar ashickur-rahman commented on August 30, 2024

Yes, you can use the toRasterImage method to achieve that. See the README.md (Rasterizing section) for an example.

My bad, I forget add I already have the SVG. So how I can call the file? In example you initialize a SVG using this
$image = new SVG(100, 100);

But I want to load the SVG I already have. Is it possible?

from php-svg.

stelgenhof avatar stelgenhof commented on August 30, 2024

If I understand what you are trying to do, have a look at the README.md file the last section. It explains how you can load an existing SVG from either a string or file.

The example outputs the resulting SVG to the browser, but you can easily save the resulting SVG to a file with for example the PHP 'file_put_contents' function.

Is that what you are looking for?

from php-svg.

ashickur-rahman avatar ashickur-rahman commented on August 30, 2024

Now I got it. But png is not rendering well.
This is the SVG

svg.zip

The code

require "vendor/autoload.php";

use SVG\SVG;

$image = SVG::fromFile("circle.svg");

$rasterImage = $image->toRasterImage(500, 500);

header('Content-Type: image/png');
imagepng($rasterImage);

image

I am not sure, what I am doing wrong?

from php-svg.

stelgenhof avatar stelgenhof commented on August 30, 2024

This might not be the best way to generate a PNG from an existing SVG file. The internal rasterization component of this library might not be able to properly render the elements in your SVG. I belief there are some limitations with rasterization in this library.

If you only are looking for a simple conversion from SVG to PNG, then I would recommend use a library such as Imagick.

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.