# Rsvg question

**URL:** <https://discourse.julialang.org/t/rsvg-question/56679>\
**Category:** New to Julia\
**Created:** [March 7, 2021, 3:43pm UTC](https://discourse.julialang.org/t/rsvg-question/56679 "2021-03-07T15:43:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hpw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hpw/32/22300_2.png) [@hpw](https://discourse.julialang.org/u/hpw)\
**Post date:** [March 7, 2021, 3:43pm UTC](https://discourse.julialang.org/t/rsvg-question/56679/1 "2021-03-07T15:43:49Z")

</div>

I cut and paste below code from the web. I am trying to convert a svg file to png.  
The problem is  
the output file has only a size of 137 bytes.  
The Mac finder displays an empty content.  
I expect the file size to be about a few k bytes.

Can someone point me to the problems ?

thanks  
HP

* * *

using Rsvg  
using Cairo

filename\_in = “/path\_to/wq.svg”  
filename\_out= “/path\_to/wQ.png”

new\_height = 100

r = Rsvg.handle\_new\_from\_file(filename\_in)  
d = Rsvg.handle\_get\_dimensions(r)

println(d.width)  
println(d.height)

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) # 20210307 not working ?

* * *

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [March 7, 2021, 3:59pm UTC](https://discourse.julialang.org/t/rsvg-question/56679/2 "2021-03-07T15:59:37Z")

</div>

Could be that you need to call Cairo.finish or something like that first

---

<div class="post-metadata">

**Author:** ![hpw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hpw/32/22300_2.png) [@hpw](https://discourse.julialang.org/u/hpw)\
**Post date:** [March 7, 2021, 4:28pm UTC](https://discourse.julialang.org/t/rsvg-question/56679/3 "2021-03-07T16:28:33Z")

</div>

I tried to insert  
Cairo.finish(cs)  
right before Cairo.write\_to\_png()  
or right after it.

Both still produced an empty file (137 bytes).  
[I also move the finish() in a few other places and no luck…]

Thanks  
HP

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [March 7, 2021, 4:39pm UTC](https://discourse.julialang.org/t/rsvg-question/56679/4 "2021-03-07T16:39:11Z")

</div>

Sounds like the file wasn’t loaded? If you want an alternative workflow, you could do:

```julia
using Luxor
s = readsvg("/tmp/test1.svg")
w, h = s.width, s.height
@png begin
    placeimage(s, centered=true)
end w h "/tmp/output.png"

```

which calls the same Cairo.jl and RSvg.jl functions.

---

<div class="post-metadata">

**Author:** ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)\
**Post date:** [March 7, 2021, 6:28pm UTC](https://discourse.julialang.org/t/rsvg-question/56679/5 "2021-03-07T18:28:11Z")

</div>

I assume something is not well-formed-svg in your input. Rsvg.jl has some test data in the /data directory. I just checked with star.svg and it works.

---

<div class="post-metadata">

**Author:** ![hpw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hpw/32/22300_2.png) [@hpw](https://discourse.julialang.org/u/hpw)\
**Post date:** [March 7, 2021, 9:36pm UTC](https://discourse.julialang.org/t/rsvg-question/56679/6 "2021-03-07T21:36:45Z")

</div>

Yes, indeed.  
I did not think of corrupted source (svg) files!!

It turns out that the svg files somehow got corrupted last night when I tried  
various snippets…

Thanks a lot.  
HP
