Skip to content

SVG support #35

Closed
Closed

Description

@emmatyping

So as not to clog up the Scratch topic.

Summary of previous discusion:

Our options are:
glsvg, which is easy and should work. Maybe be issues with multiple svgs at the same time (which is a problem).

pyrsvg, a standard for vector raserization. Requires the hefty GTK libraries though.

Wrapping a C++ solution? nanosvg seems like a possibility, but at this point it might even be easier to write a rasterizer (and use an existing Python parser).

pinging @BookOwl and @Tymewalk please fill in anything I missed.

Activity

  1. Tymewalk commented on Mar 29, 2016

    @Tymewalk
    Member

    I think we should start with glsvg and then try to push as many SVGs into the program as we can. If the maximum number turns out to be something like 1000, we can probably say "It's OK" since I doubt anyone would use 1000 SVGs anyways. 😛

  2. emmatyping commented on Mar 30, 2016

    @emmatyping
    ContributorAuthor

    So, you aren't getting 1000 SVGs. You get one. I just tested glsvg, and well, the bug reported here is accurate. I will see if I can maybe fix this bug, but that is a significant issue. Also, if your curious, my code example that only renders one SVG.

    I'll report back if I make any progress

    Oh, or as an utter hack, we might be able to try off screen rasterization using glsvg, then deal only in bitmaps. Either way, I will experiment with what is possible.

  3. BookOwl commented on Mar 30, 2016

    @BookOwl
    Member

    So, you aren't getting 1000 SVGs. You get one.

    That's really bad.

    Oh, or as an utter hack, we might be able to try off screen rasterization using glsvg, then deal only in bitmaps

    That sounds like it could work.

    I'm starting to think that writing our own rasterizer might be the best option.

  4. Tymewalk commented on Mar 30, 2016

    @Tymewalk
    Member

    So, you aren't getting 1000 SVGs. You get one.

    YIKES.
    How big are the GTK libraries, and do they come installed by default? I'm considering pyrsvg.

    Oh, or as an utter hack, we might be able to try off screen rasterization using glsvg, then deal only in bitmaps

    Will it slow things down if we use it a lot? Or if a sprite constantly rescales itself?

  5. BookOwl commented on Mar 30, 2016

    @BookOwl
    Member

    @Tymewalk, if we do offscreen rasterization, I think that we would do it once and scale and rotate the rasterized image.

  6. Tymewalk commented on Mar 30, 2016

    @Tymewalk
    Member

    @BookOwl OK, so here's how I understand the workflow:

    • User makes a Slither sprite
    • User adds an SVG costume to it with height and width
      • glsvg rasterizes it
      • The rasterized image goes into the costumes list
    • Continue as if it was just a bitmap
  7. emmatyping commented on Mar 30, 2016

    @emmatyping
    ContributorAuthor

    If we go the route of rasterize once, we will need to rasterize at a high resolution, else we might get bad scaling. Which would increase time to rasterize. I will try to work on this today and tomorrow. The documentation for PyOpenGL is not the best, but I think I can piece things together.

    @Tymewalk I think we can just add a little bit to where people add the costume (I assume they must give a file path), if it has an svg or svgz file extension, we use glsvg and off screen rendering.

  8. BookOwl commented on Mar 30, 2016

    @BookOwl
    Member

    If we go the route of rasterize once, we will need to rasterize at a high resolution, else we might get bad scaling. Which would increase time to rasterize

    It might be a good idea to look into creating our own SVG renderer.

    will try to work on this today and tomorrow. The documentation for PyOpenGL is not the best, but I think I can piece things together.

    Thanks for working on it!

  9. emmatyping commented on Mar 30, 2016

    @emmatyping
    ContributorAuthor

    It might be a good idea to look into creating our own SVG renderer.

    Whew, that would be a lot of work. Maybe. I would rather wrap a C++ one for speed.

    Also, as for speed of the rasterization, I have no idea. I will have to experiment. OpenGL uses the GPU, so it should be fast, but with Python.... I don't know.

    As for pyrsvg, it is not included in the Python distribution, and depends on the GTK+ runtime (I just checked install size ~165mb).

  10. Tymewalk commented on Mar 30, 2016

    @Tymewalk
    Member

    @ironmanmark20 Yeah, they do specify a file path. With split it shouldn't be too hard to check.

    As for pyrsvg, it is not included in the Python distribution, and depends on the GTK+ runtime (I just checked install size ~165mb).

    I was asking if GTK comes pre-installed, but I'll take that as a no.
    165 MB is a little much. Maybe there could be a no-SVG version of Slither that doesn't require it?

    Or maybe it checks if GTK is installed, and if not, doesn't support SVGs, but still lets you use Slither without them.

  11. 38 remaining items

  12. Tymewalk commented on Sep 11, 2016

    @Tymewalk
    Member

    @BookOwl Then what to do if they don't have it installed?

    Will we just warn them or is it a hard dependency?

  13. BookOwl commented on Sep 11, 2016

    @BookOwl
    Member

    We could say that if they have node.js installed we will be able to handle svgs, otherwise we will throw an error when the user tries to use a svg just like we do now.

  14. Tymewalk commented on Sep 11, 2016

    @Tymewalk
    Member

    OK. In the installation instructions we can also include that they have to install that module.

    Where would the rasterized PNGs go, though?

  15. BookOwl commented on Sep 11, 2016

    @BookOwl
    Member

    We could create a cache dir to put the pngs in and then delete it when we exit. Also, I think that it should be possible to get the setup.py to install it for us.

  16. Tymewalk commented on Sep 11, 2016

    @Tymewalk
    Member

    @BookOwl OK then.

    Should we remove the "hard" label? It seems like it's just a matter of getting a new program to play nice with our code.

  17. emmatyping commented on Sep 11, 2016

    @emmatyping
    ContributorAuthor

    You can run arbitrary python code in setup.py, so installing it shouldn't be a problem

  18. BookOwl commented on Sep 12, 2016

    @BookOwl
    Member

    @Tymewalk @ethanhs, I just found out that if we restrict ourselves to just Python 3.4+, we can use CarioSVG to rasterize the SVGs to PNGs. They say that it works on all platforms, and installing it is as easy aspip install cairosvg, so we could add it as a dependency.

  19. BookOwl commented on Sep 12, 2016

    @BookOwl
    Member

    OK, it turns out that the user still needs to have cairo installed, BUT, I've found out that it should be easy to build a stand-alone cairo DLL that we can include for Windows, and we just need to run a simple shell command to get it to install on OS X and Linux.

  20. BookOwl commented on Sep 12, 2016

    @BookOwl
    Member
  21. BookOwl commented on Sep 12, 2016

    @BookOwl
    Member

    I started a PR in #81

  22. added this to the v0.4.0 milestone on Sep 12, 2016
  23. BookOwl commented on Sep 13, 2016

    @BookOwl
    Member

    PR #83 adds this

  24. Tymewalk commented on Sep 19, 2016

    @Tymewalk
    Member

    #83 was just merged. Which means that after half a year, Slither FINALLY supports SVGs.

    It is beautiful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions