GithubHelp home page GithubHelp logo

Comments (4)

liZe avatar liZe commented on June 9, 2024

Yes, the size is currently truncated.

It seems obvious that rounding would be a perfect idea … but it’s not 😄.

If your SVG’s size is 10.5px, with a 10.5px white square for the background, you want to get a white PNG, and not semi-transparent pixels on the right and the bottom. So, unfortunately, rounding the surface size is not perfect in all cases.

What if we add a scale factor of 11/10.5 before rendering? That would avoid the transparent pixels (if floating point arithmetic gods love you), but we would lose pixel alignment and get blurry rendering even for horizontal and vertical lines. So, even rounding + scaling is not perfect.

So… I’m not sure about what to do here.

Even my image viewer is "broken" with this SVG file 😢
Capture d’écran du 2024-03-06 14-37-06

Half pixels are devil.

from cairosvg.

judge2005 avatar judge2005 commented on June 9, 2024

I think it would be easiest(?) to just provide options that allow the user to define what behavior they want, i.e. specify the rounding and/or specify a border to grow the rendering surface. That way the user has some tools to manage the conversion and you don't break the existing functionality.

from cairosvg.

liZe avatar liZe commented on June 9, 2024

Let’s round values. It’s not perfect, but nobody will ever complain. 😄

from cairosvg.

liZe avatar liZe commented on June 9, 2024

Let’s round values. It’s not perfect, but nobody will ever complain. 😄

Except tests, of course…

from cairosvg.

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.