Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with certain width/height and pixel ratio for svg images #2

Open
pathmapper opened this issue Jul 23, 2020 · 1 comment
Open

Comments

@pathmapper
Copy link

pathmapper commented Jul 23, 2020

Steps to reproduce:

Use the CLI with:

{"id": "green", "url": "{base_url}/images/green.svg", "width": 200, "height": 200},

http://localhost:8080/acme/[email protected]

Error: Expected number between 1 and 2400 for density but received 2880 of type number

With
https://cdn.jsdelivr.net/gh/maputnik/osm-liberty@gh-pages/svgs/svgs_iconset/airport_11.svg
this happens with "width": 200, "height": 200 and @3x.

So for more complex SVGs this seems to happen at a lower width/height and pixel ratio.

@orangemug
Copy link
Owner

It's kind of an odd one, because the density is based on the width/height of the input SVG. Which is defined by the width/height attributes.

<svg width="20" height="20">
  <!-- ... -->
</svg>

So sharp seems to only allow a max density of 2400, however if you where to change the the SVG to width/height 200 instead

<svg width="200" height="200">
  <!-- ... -->
</svg>

Then you wouldn't need such a high density. If a viewBox is present on the SVG as it is in the case of green.svg then it'd 'just work' however I believe if it's missing a viewBox.... hmm I'm not actually sure what happens if we're missing a viewBox attribute would need to do some tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants