8

In QGIS 3.4 I have imported my customised icon (which was obtained through the .jpeg image conversion) for point layers using an SVG file.

This works well except for the fact that the original colour was replaced by black.

Under the "Symbology" menu I cannot change the colour of the "SVG marker" (see picture below).

If I try to change it in the level above under "Marker" this does not change the colour of the icon. Any ideas or suggestions?

Example

Here is the code of my SVG (opened in Browser):

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg version="1.0" xmlns="http://www.w3.org/2000/svg" width="260.000000pt" height="390.000000pt" viewBox="0 0 260.000000 390.000000" preserveAspectRatio="xMidYMid meet">
<g transform="translate(0.000000,390.000000) scale(0.100000,-0.100000)" fill="#000000" stroke="none">
    <path d="M1163 3850 c-217 -23 -457 -120 -639 -261 -129 -99 -270 -272 -346
    -424 -92 -183 -130 -349 -130 -565 -1 -351 118 -638 366 -886 180 -180 367
    -283 611 -339 l100 -22 0 -264 0 -264 -237 -3 -238 -2 0 -170 0 -170 238 -2
    237 -3 3 -237 2 -238 170 0 170 0 2 238 3 237 238 3 237 2 0 170 0 170 -237 2
    -238 3 0 264 0 264 100 22 c244 56 431 159 611 339 185 185 290 380 345 639
    31 144 31 362 -1 502 -58 259 -161 447 -344 631 -185 184 -394 297 -646 348
    -97 19 -273 27 -377 16z m362 -369 c263 -69 477 -246 595 -493 66 -138 84
    -220 83 -388 0 -175 -18 -255 -92 -405 -108 -220 -311 -392 -545 -464 -101
    -31 -96 -35 -96 73 l0 93 92 53 c241 137 374 295 386 460 9 124 -33 188 -138
    212 -41 9 -74 8 -181 -6 -186 -26 -252 -14 -312 54 -22 24 -33 29 -50 24 -60
    -19 -87 -124 -52 -199 26 -54 65 -83 132 -99 55 -12 69 -12 122 1 33 9 68 13
    76 9 25 -9 1 -43 -43 -61 -59 -25 -133 -9 -277 61 -117 56 -205 72 -302 55
    -78 -14 -112 -32 -149 -82 -43 -59 -56 -122 -43 -212 9 -62 18 -87 43 -120 53
    -70 170 -125 291 -136 l60 -6 3 -97 c3 -113 8 -109 -94 -77 -190 59 -373 192
    -484 354 -46 68 -107 203 -132 292 -31 112 -30 334 1 448 94 350 368 603 724
    671 98 19 279 11 382 -15z"/>
    <path d="M1363 3270 c-38 -15 -63 -121 -70 -292 -7 -167 4 -217 58 -263 94
    -78 187 18 227 235 22 117 24 165 6 209 -19 49 -53 75 -130 101 -64 22 -61 22
    -91 10z"/>
    <path d="M1140 3243 c-69 -24 -121 -63 -155 -117 -28 -46 -30 -56 -27 -130 3
    -97 26 -214 54 -273 20 -42 59 -73 91 -73 13 0 77 63 77 75 0 2 11 46 25 97
    34 123 56 300 45 358 -5 26 -17 52 -30 62 -26 21 -23 21 -80 1z"/>
    <path d="M1685 3140 c-28 -31 -76 -250 -77 -352 0 -67 37 -124 87 -134 48 -9
    60 4 109 106 34 72 40 97 44 167 4 79 3 85 -27 131 -37 58 -56 77 -93 91 -21
    8 -29 6 -43 -9z"/>
    <path d="M744 3008 c-61 -41 -76 -78 -68 -168 16 -177 106 -329 194 -329 44
    -1 52 13 63 102 9 70 7 110 -7 224 -10 76 -24 153 -32 171 -12 29 -17 32 -57
    32 -34 0 -57 -8 -93 -32z"/>
</g>
</svg>
3
  • which software did you use to create the svg?
    – Mazu_R
    Commented Dec 6, 2018 at 12:22
  • I downloaded a jpeg image and converted it online to svg. This worked fine for another icon (although to be fair, that one was black to start with). @Taras where can I find the code?
    – Papayapap
    Commented Dec 6, 2018 at 12:27
  • doing the second way, I extract the code above
    – Papayapap
    Commented Dec 6, 2018 at 12:38

4 Answers 4

18

You can simply do it directly in QGIS via Layer Properties > Draw Effects > Effect Properties.

Open your SVG Layer Properties and click Draw Effects and then open the Star symbol Customize effects Customize_effects.

SVG_Layer_Properties

Then use Colorise as an Effect type

Effect_properties


References:

5
  • This is indeed easier!
    – Papayapap
    Commented Dec 6, 2018 at 13:03
  • @Felix, if my or another suggestion (from J.R or Erik) solves your problem, please accept it as a valid answer.
    – Taras
    Commented Dec 6, 2018 at 13:15
  • All of them work, I chose this one because it is the easiest to me.
    – Papayapap
    Commented Dec 6, 2018 at 13:37
  • I am wondering which brightness I have to chose to get the exat color which I chose in the color picker for areas which were black in the SVG.
    – Alex
    Commented Jan 6, 2023 at 17:19
  • Have you tried 0?
    – Taras
    Commented Jan 8, 2023 at 11:46
16

You need to edit the SVG file and replace the

fill="#000000" stroke="none"

by something like

fill="param(fill) #FFF" stroke="param(outline) #000" stroke-width="param(outline-width) 1"

the "param(xxx)" part allow you to set the xxx parameter from the qgis interface, the #XXX part is the default color.

For a more detailled explanation see this answer How to create svg symbols that have modifiable fill color, stroke color and stroke width?

1
  • This is the best answer, IMO, as it also enables changing styling of image objects in the map composer. I've been doing this for SVG images for a while now when I wanted to be able to style logos directly in the composer and this method doesn't require to dig into a couple dialogs to change the color.
    – Gabriel
    Commented Dec 6, 2018 at 13:58
3

Using notepad++ (or any other decent text editor) simply change in this part

<g transform="translate(0.000000,390.000000) scale(0.100000,-0.100000)" fill="#000000" stroke="none">

the code for "fill" to any desired color. E.g. fill="rgb(0,255,0)" for a green symbol.

2
  • great, I will download notepad++. However, as I have no clue with this, may I also ask how the code would be for a dark pink / purple colour?
    – Papayapap
    Commented Dec 6, 2018 at 12:49
  • Feel free to google for a website which gives you RGB-codes for any color you like. E.g. rapidtables.com/web/color/RGB_Color.html
    – Erik
    Commented Dec 6, 2018 at 13:05
0

Using Inkscape, simply saving the file in the format Plain SVG, rather than Inkscape SVG will work without any need to edit the file afterwards. Plain SVG uses parameters like QGIS instead of a style setting.

However, this appears to only work if there are just two objects in the icon, any more and not all the colours, etc will change within QGIS settings. Perhaps someone can provide a workaround for this.

For example:

This is the code of an icon/file saved in Inkscape SVG

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->

<svg
   width="100"
   height="100"
   viewBox="0 0 26.458333 26.458333"
   version="1.1"
   id="svg1"
   inkscape:version="1.3.2 (1:1.3.2+202311252150+091e20ef0f)"
   sodipodi:docname="landuse_symbol.svg"
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:svg="http://www.w3.org/2000/svg">
  <sodipodi:namedview
     id="namedview1"
     pagecolor="#ffffff"
     bordercolor="#000000"
     borderopacity="0.25"
     inkscape:showpageshadow="2"
     inkscape:pageopacity="0.0"
     inkscape:pagecheckerboard="0"
     inkscape:deskcolor="#d1d1d1"
     inkscape:document-units="mm"
     inkscape:zoom="5.45"
     inkscape:cx="50"
     inkscape:cy="35.321101"
     inkscape:window-width="1440"
     inkscape:window-height="742"
     inkscape:window-x="0"
     inkscape:window-y="0"
     inkscape:window-maximized="1"
     inkscape:current-layer="layer1" />
  <defs
     id="defs1" />
  <g
     inkscape:label="Layer 1"
     inkscape:groupmode="layer"
     id="layer1">
    <circle

fill="param(fill) #00ffff" stroke="param(outline) #000000" stroke-width="param(outline-width) 0.395835"
       id="path1"
       cx="13.229167"
       cy="13.229167"
       r="13.031249" />
    <path
       style="fill:#00ffff;stroke:#000000;stroke-width:0.390181"
       d="M 13.109259,26.215461 V 0.6672652 L 25.792503,13.558712 H 13.076272"
       id="path2" />
  </g>
</svg>

And this is the same icon/file saved in 'Plain SVG'

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->

<svg
   width="100"
   height="100"
   viewBox="0 0 26.458333 26.458333"
   version="1.1"
   id="svg1"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:svg="http://www.w3.org/2000/svg">
  <defs
     id="defs1" />
  <g
     id="layer1">
    <circle
       fill="param(fill) #00ffff"
       stroke="param(outline) #000000"
       stroke-width="param(outline-width) 0.395835"
       id="path1"
       cx="13.229167"
       cy="13.229167"
       r="13.031249" />
    <path
       style="fill:#00ffff;stroke:#000000;stroke-width:0.390181"
       d="M 13.109259,26.215461 V 0.6672652 L 25.792503,13.558712 H 13.076272"
       id="path2" />
  </g>
</svg>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.