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

How to set DPI in the minimal example #526

Closed
topochico-one opened this issue Jul 19, 2022 · 6 comments
Closed

How to set DPI in the minimal example #526

topochico-one opened this issue Jul 19, 2022 · 6 comments

Comments

@topochico-one
Copy link

Is it possible to set dpi for the output png file in the minimal example?

Adding opt.dpi = 300.0; on line 12 did not seem to affect the output.

I am sorry for such a basic question. I am completely new to resvg and image processing in general.

@RazrFalcon
Copy link
Collaborator

I should improve Options::dpi docs... What result do you expect from this setting? This option doesn't "scale" the image (you should use --zoom instead). This option doesn't affect DPI of the produced PNG.
All it does, is affects how relative units (cm, in, etc.) would be converted into pixels. That's it.

@topochico-one
Copy link
Author

Thank you for explaining! I would like to increase the DPI of the produced PNGs. Right now, the minimal example outputs PNGs with DPI of 72 pixels/inch. Is it possible to increase it?

@RazrFalcon
Copy link
Collaborator

It's not possible and doesn't really makes sense. Why would you want this?

@topochico-one
Copy link
Author

I am sorry -- I know very little about these things. I just want to generate sharper PNGs. For example, when I export my artwork in Adobe Illustrator, I can set image resolution by specifying PPI. I want to be able to do the same for the artwork I generate programmatically in Rust.

@RazrFalcon
Copy link
Collaborator

RazrFalcon commented Jul 20, 2022

PNG is a raster format, it has a fixed "resolution". I'm not sure how Illustrator loads PNGs and if it cares about the DPI property, but you can try rendering your SVG at higher resolution. Like --zoom 4 via CLI or usvg::FitTo::Zoom(4.0) via code.

While PNG indeed has a "resolution"/DPI property, it has nothing to do with SVG DPI and cannot be written at the moment anyway, because the png crate doesn't support it.

@topochico-one
Copy link
Author

I see -- thank you so much for explaining!

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