# How to convert an svg file to png with fixed pixel size/resolution

**URL:** https://discourse.julialang.org/t/how-to-convert-an-svg-file-to-png-with-fixed-pixel-size-resolution/33561
**Category:** General Usage
**Tags:** question
**Created:** [January 19, 2020, 11:07pm UTC](https://discourse.julialang.org/t/how-to-convert-an-svg-file-to-png-with-fixed-pixel-size-resolution/33561 "2020-01-19T23:07:56Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![hhaensel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hhaensel/32/1207_2.png) [@hhaensel](https://discourse.julialang.org/u/hhaensel)
#### Post date: [January 20, 2020, 4:06pm UTC](https://discourse.julialang.org/t/how-to-convert-an-svg-file-to-png-with-fixed-pixel-size-resolution/33561/2 "2020-01-20T16:06:13Z")

</div>

I did find the solution myself 🙂

```julia
new_height = 48
r = Rsvg.handle_new_from_file(filename_in)
d = Rsvg.handle_get_dimensions(r)
scalingfactor = new_height / d.height
cs = Cairo.CairoImageSurface(round(Int,d.width * scalingfactor), new_height, Cairo.FORMAT_ARGB32)
c = Cairo.CairoContext(cs)
Cairo.scale(c, scalingfactor, scalingfactor)
Rsvg.handle_render_cairo(c,r)
Cairo.write_to_png(cs,filename_out)

```

Edit: I was inspired by the [rsvg manual](https://developer.gnome.org/rsvg/stable/RsvgHandle.html#rsvg_handle_set_size_callback)

---

_[View the full topic](https://discourse.julialang.org/t/how-to-convert-an-svg-file-to-png-with-fixed-pixel-size-resolution/33561)._
