GithubHelp home page GithubHelp logo

Comments (5)

meyfa avatar meyfa commented on July 26, 2024 3

The problem seems to stem from the fact that the rasterizer treats every subpath as being completely unrelated to the previous ones, without taking into account that SVG imposes certain fill rules for cases where subpaths overlap.

I have no idea yet how to fix this, but it definitely needs attention.

Thanks again for reporting the problem!

from php-svg.

meyfa avatar meyfa commented on July 26, 2024 1

This will probably come as a surprise to everyone involved (myself included), but I finally implemented this. See PR #136.
The icon now renders just fine using the exact same code from above:

search

I'd thank you for your patience, but I doubt this is still useful to any of the original participants of this discussion. Still it will hopefully benefit people that ran into this more recently!

from php-svg.

meyfa avatar meyfa commented on July 26, 2024

Thanks for opening this issue, I'm looking into it.

from php-svg.

winkbrace avatar winkbrace commented on July 26, 2024

Really unfortunate since this is quite an important requirement. It would have been so nice to be able to do this without phantom.js :/

I've tried to come up with a way to calculate the inner space and redraw a transparent layer over it, but that's rather difficult and won't even solve all cases. It's far easier to make the final transformation step with a nodejs tool like svg2png.

from php-svg.

andykirk avatar andykirk commented on July 26, 2024

I came across this issue and though I'd post my solution to rendering the PNG, using Imagick:

// Save the SVG first:
// ($image is the SVG as per docs, $svg_filename is the path and name of file to output)
file_put_contents($svg_filename, $image->toXMLString());

// Create a new Imagick:
$im = new Imagick();
$im->readImageBlob(file_get_contents($svg_filename));

// This is for PNG24, but can be any output Imagick supports:
$im->setImageFormat("png24");

// $png_filename is the file path and name for resultant raster image:
$im->writeImage($png_filename);
$im->clear();
$im->destroy();

Hope that helps someone.

Cheers

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.