Page 1 of 1

Put an image svg on jpg, problem background white

Posted: 2018-11-23T06:49:28-07:00
by alexxxb62
Hello

I want to put an image svg on a jpg image.
To do that I use Imagick
Here is the code:

Code: Select all

// Prepare Map
$map = new \Imagick();
$map->newImage($formatSize_width, $formatSize_height, new \ImagickPixel($backgroundColor));
$map->setImageFormat("jpg");
$map->setImageUnits(imagick::RESOLUTION_PIXELSPERINCH);
$map->setResolution(300,300);

$draw_water2 = new \Imagick();
$draw_water2->readImage($WaterPathSvgOutput);
$map->compositeImage($draw_water2, \Imagick::COMPOSITE_ATOP, 0, 0);
$draw_water2->clear();

$map->writeImage($MapPath); 
He adds my svg over my jpg, but he adds a white background on my svg. So I do not see my background image anymore
Do you have any idea where this may come from?

thank you in advance
Alexandre

Re: Put an image svg on jpg, problem background white

Posted: 2018-11-23T11:06:23-07:00
by fmw42
Post your SVG image and tell us what version of ImageMagick is being used. Perhaps you need to set the background color to transparent before reading the SVG image.

Re: Put an image svg on jpg, problem background white

Posted: 2018-11-23T20:05:05-07:00
by alexxxb62
Hello,

imagick module version : 3.2.0RC1
ImageMagick version : 6.8.9-9 Q16

and my svg :

Code: Select all

<?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="4724.444444pt" height="4724.444444pt" viewBox="0 0 4724.444444 4724.444444"
 preserveAspectRatio="xMidYMid meet">
<metadata>
Created by potrace 1.12, written by Peter Selinger 2001-2015
</metadata>
<g transform="translate(0.000000,4724.444444) scale(0.218724,-0.218724)"
fill="#7CC7C8" stroke="none">
<path d="M11538 21600 l-95 0 -32 -122 c-18 -68 -45 -168 -60 -223 -16 -55
-43 -153 -61 -217 l-33 -118 -32 -37 c-17 -21 -51 -66 -74 -101 -24 -35 -53
-87 -66 -115 l-24 -52 -15 -110 c-9 -60 -24 -166 -35 -235 l-19 -125 -52 -160
c-29 -88 -61 -187 -72 -219 -10 -32 -38 -95 -62 -140 -24 -45 -58 -109 -76
-144 l-33 -63 -30 -15 -29 -16 -38 -81 -37 -82 -8 -45 -8 -45 -67 -90 c-37
-49 -88 -114 -114 -142 l-48 -53 -23 0 -22 0 -125 -157 c-68 -87 -157 -203
-199 -258 -41 -55 -95 -129 -120 -165 -25 -36 -67 -96 -94 -135 -27 -38 -66
-95 -87 -125 l-38 -55 -137 -118 c-76 -65 -215 -177 -310 -247 l-172 -129 -3
-33 -3 -32 -95 -77 -94 -77 -11 -31 -10 -30 -80 -68 c-45 -37 -96 -81 -114
-96 l-33 -28 17 -19 17 -19 57 28 c31 16 94 54 140 86 46 31 85 54 88 51 3 -2
-10 -60 -28 -128 -17 -67 -35 -145 -40 -173 -4 -27 -8 -92 -8 -144 l-1 -95 21
-75 21 -75 137 -181 c75 -99 204 -268 286 -375 82 -107 232 -303 334 -435
l185 -240 7 -55 c4 -30 13 -152 19 -270 6 -118 17 -345 25 -504 l14 -288 -34
-70 -34 -70 -126 -133 -126 -134 23 -21 23 -21 27 5 c14 3 68 26 120 51 l94
46 62 105 62 106 -5 46 c-3 26 -14 220 -25 432 -11 212 -25 475 -31 585 l-11
199 -126 166 c-70 91 -228 298 -352 460 -125 162 -283 370 -352 461 l-125 166
-24 74 -24 74 1 55 2 55 37 225 38 225 16 17 c9 9 62 48 118 85 l102 68 228
221 c125 121 263 253 306 294 l77 73 0 33 0 33 173 208 c95 114 207 251 249
303 41 52 104 136 139 185 34 50 89 120 120 157 32 37 63 76 69 88 l11 20 23
-6 22 -5 12 38 12 38 108 115 109 115 38 70 c21 39 75 133 120 210 l81 140 59
180 59 180 7 135 7 135 15 65 c8 36 29 119 46 185 18 66 55 188 83 270 28 83
61 170 73 195 13 25 41 65 62 90 l39 45 53 215 c30 118 56 221 58 228 l5 12
-94 0z"/>
<path d="M1889 19780 c-4 0 -32 -20 -62 -45 l-55 -45 -7 -30 -6 -30 5 -18 6
-18 39 -22 38 -22 64 41 c35 23 68 45 73 49 l9 9 -49 65 c-26 36 -51 66 -55
66z"/>
<path d="M10565 18720 l-15 0 0 -92 0 -93 24 -50 c12 -27 54 -95 91 -150 38
-55 86 -126 107 -158 21 -31 52 -86 68 -121 17 -35 30 -74 30 -85 0 -11 9 -77
21 -147 l20 -126 62 -74 62 -75 75 -23 75 -24 3 -28 c2 -15 1 -41 -2 -58 l-6
-31 -161 -105 c-89 -58 -165 -106 -169 -108 -4 -2 -53 28 -109 66 l-101 69
-87 -18 c-49 -10 -107 -19 -129 -19 l-42 0 -5 23 c-3 12 -28 90 -57 172 -29
83 -54 152 -56 153 -1 2 -12 1 -25 -3 -12 -4 -69 -43 -128 -88 -58 -44 -149
-116 -201 -160 -52 -44 -103 -89 -113 -100 l-17 -20 11 -13 c6 -8 15 -14 20
-14 l9 0 0 23 0 24 93 60 c50 33 140 99 199 146 59 48 112 87 116 87 l9 0 33
-82 c18 -46 44 -117 57 -158 14 -41 29 -82 34 -92 l9 -16 42 12 c24 7 84 21
134 31 l91 18 74 -49 c41 -27 88 -60 105 -73 l31 -22 134 86 c74 48 147 96
162 107 l29 20 73 -71 c40 -39 76 -71 80 -71 l6 0 -7 13 c-4 6 -32 43 -62 80
l-54 68 7 39 7 40 10 0 c5 0 18 -4 28 -10 l18 -10 37 -72 c21 -40 56 -100 78
-133 22 -33 73 -102 114 -152 41 -51 77 -93 79 -93 2 0 11 17 19 37 9 20 14
40 13 43 -2 4 -46 53 -98 110 l-95 102 -36 57 c-20 31 -61 94 -91 141 l-55 85
-96 50 -97 50 -10 36 -10 35 -34 40 -34 40 -13 138 -13 139 -38 60 c-22 32
-83 114 -138 182 l-98 122 -27 119 -26 119 -15 23 -14 22 -15 0z"/>
<path d="M8193 16697 l-11 4 -94 -77 c-51 -42 -100 -83 -110 -91 l-16 -15
-107 -24 -107 -25 -126 -107 c-70 -58 -156 -131 -192 -161 -36 -30 -105 -89
-155 -130 -49 -42 -130 -114 -178 -161 -49 -47 -127 -128 -173 -181 l-84 -97
-43 -78 c-24 -44 -69 -126 -99 -184 -30 -58 -62 -125 -71 -150 -9 -25 -34
-103 -56 -175 l-41 -130 -14 -115 -15 -116 14 -239 c8 -132 15 -297 15 -367
l0 -127 -62 -29 c-35 -17 -142 -56 -238 -87 -96 -31 -196 -64 -223 -74 l-48
-17 -90 -99 c-49 -55 -140 -163 -201 -240 l-112 -140 -53 -43 c-29 -24 -145
-112 -257 -195 -113 -84 -258 -187 -323 -229 -65 -42 -176 -119 -248 -172
l-130 -96 -75 -104 c-41 -57 -164 -227 -273 -379 l-198 -275 -47 -38 c-26 -21
-94 -77 -151 -124 -57 -47 -172 -143 -255 -213 -83 -71 -197 -171 -253 -223
l-101 -94 5 -20 5 -20 -17 6 -17 7 -474 -474 c-261 -261 -474 -476 -474 -479
0 -3 14 -21 30 -40 l29 -35 269 269 269 268 69 -60 c38 -32 94 -86 125 -118
l55 -59 17 -68 17 -67 -30 -128 c-16 -70 -32 -137 -35 -149 l-5 -22 -56 -63
c-30 -35 -64 -79 -74 -99 l-19 -37 -38 -8 -38 -8 -470 3 -470 3 -11 14 -12 15
-388 -11 -389 -11 -25 -24 -25 -24 -125 -21 c-69 -11 -169 -27 -222 -35 l-97
-15 -26 10 -25 10 -143 -56 c-78 -30 -195 -75 -259 -100 l-118 -46 0 -110 0
-110 13 5 c6 3 46 19 87 36 41 16 129 51 195 77 66 25 152 56 190 69 39 12
104 32 145 43 41 11 116 27 165 36 50 8 135 22 190 30 55 8 143 20 195 27 l95
12 430 -8 c237 -4 493 -10 570 -14 l140 -6 5 -259 5 -259 58 1 c31 0 61 1 65
1 l9 1 7 233 c3 127 9 244 12 259 l6 27 342 4 341 4 35 11 c19 6 98 23 175 38
77 14 167 35 200 47 33 11 83 28 110 38 28 9 129 46 225 82 l175 64 190 112
189 112 17 -22 17 -23 -4 -10 c-2 -6 -13 -108 -24 -226 -11 -118 -27 -291 -35
-385 -8 -93 -17 -178 -19 -187 l-4 -18 9 -5 8 -6 58 17 c32 9 61 19 65 23 l7
6 16 165 c9 91 22 239 30 330 8 91 19 208 25 260 5 52 12 125 15 162 l6 67 82
70 c45 38 125 116 178 172 52 57 131 145 175 194 l81 90 153 210 c85 116 173
237 196 270 24 33 103 141 175 240 73 99 160 218 194 265 33 47 110 153 170
235 60 83 154 213 209 289 56 77 121 168 146 203 25 34 95 131 155 215 61 84
119 166 131 183 11 16 37 54 58 84 l38 53 -9 9 c-4 4 -28 13 -53 18 l-45 11
-20 -27 c-11 -14 -37 -48 -58 -75 -21 -27 -41 -47 -44 -45 -2 3 5 54 17 114
l22 108 -17 47 -16 47 10 19 c5 10 17 24 25 32 l16 12 0 249 0 248 22 12 22
12 111 0 110 1 35 -12 35 -12 37 -60 38 -59 27 -18 c16 -10 61 -41 102 -70
l74 -53 47 0 47 0 69 -36 c38 -21 110 -62 159 -92 50 -30 141 -86 202 -123
l113 -67 42 10 c24 6 84 22 133 35 50 13 146 40 215 60 69 19 148 41 175 48
28 7 82 22 120 33 39 11 142 41 230 66 l160 46 107 44 c58 24 129 55 156 67
l49 24 -9 33 -9 33 -13 5 -14 5 -188 -74 c-104 -41 -232 -86 -284 -101 -52
-15 -149 -43 -215 -63 -66 -19 -167 -48 -225 -64 l-105 -29 -226 0 -226 0
-254 146 c-140 81 -281 161 -314 180 l-60 33 -71 73 -71 73 -78 128 c-44 70
-90 138 -103 152 l-23 25 -82 0 -83 0 -16 28 c-9 15 -21 44 -26 66 l-11 39 19
16 20 16 -11 185 -11 185 6 66 c3 37 17 123 30 192 14 69 37 160 51 203 l26
77 69 136 c38 75 102 188 142 252 l73 117 171 140 c94 77 217 174 272 215 56
42 126 90 156 108 l54 32 20 42 20 41 163 125 163 124 63 80 64 80 -3 19 -3
19 -12 4z m-1680 -2878 l27 1 0 -293 0 -293 -9 -10 c-5 -5 -18 -45 -30 -89
-11 -44 -32 -129 -46 -190 -14 -60 -32 -136 -41 -168 -8 -32 -31 -93 -51 -135
-20 -42 -60 -128 -89 -190 l-54 -114 -117 -158 c-65 -87 -154 -209 -198 -271
-44 -62 -84 -120 -89 -130 l-8 -17 16 -53 15 -54 -58 -79 -58 -80 -86 -30 -86
-31 -158 -215 c-87 -118 -197 -263 -243 -321 -47 -58 -143 -176 -215 -261
l-130 -154 -126 -107 c-69 -59 -164 -135 -210 -170 -46 -35 -111 -79 -144 -99
-33 -20 -114 -63 -180 -96 -66 -32 -156 -75 -200 -95 l-80 -35 -115 -31 c-63
-16 -158 -41 -210 -55 -52 -14 -122 -32 -154 -41 l-60 -16 -60 32 c-34 18 -80
45 -103 61 l-43 29 0 24 c0 14 17 93 37 177 l36 152 47 70 c26 39 53 82 60 95
l12 24 -17 80 -17 79 50 52 50 51 6 43 6 42 -70 119 c-38 65 -70 124 -70 130
l0 11 24 0 24 0 49 58 c27 31 65 78 86 104 l37 47 308 240 307 240 31 38 c17
21 64 88 105 148 41 61 110 166 155 235 44 69 111 173 147 231 l68 107 156
117 c85 65 174 136 197 158 l41 40 75 44 c41 25 122 80 180 122 58 43 130 93
160 113 30 19 89 66 130 103 41 38 115 107 163 154 l88 86 80 112 80 112 72
27 c40 15 88 33 107 41 19 8 91 35 160 60 69 25 143 51 165 58 22 8 52 14 68
14z"/>
<path d="M8538 16510 l-57 0 -11 -20 -10 -19 35 -208 35 -208 21 -17 c12 -10
26 -18 31 -18 6 0 37 26 71 59 l61 59 -22 52 -22 53 18 31 19 31 37 -2 37 -2
10 26 10 26 -23 56 c-12 31 -27 61 -32 68 l-11 12 -70 10 c-39 6 -96 11 -127
11z m82 -63 l94 -7 23 -22 c13 -12 23 -24 23 -27 0 -3 -36 -44 -79 -91 l-79
-85 -25 23 -25 23 -6 62 c-4 34 -10 77 -13 96 l-6 34 93 -6z"/>
<path d="M8139 15735 l-17 6 -24 -33 c-14 -18 -77 -104 -141 -190 -64 -86
-121 -159 -126 -163 -5 -3 -66 -8 -134 -12 l-124 -6 -7 -111 -7 -111 -12 -11
c-7 -6 -30 -18 -52 -27 -22 -9 -83 -32 -135 -52 -52 -20 -130 -50 -172 -67
l-77 -30 -20 -34 -20 -33 154 -198 155 -198 0 -15 c0 -8 -23 -60 -50 -114
l-50 -99 14 -21 13 -21 68 -19 68 -19 24 -21 24 -21 9 -155 c6 -85 11 -184 12
-220 l3 -65 47 -3 48 -3 -5 43 c-3 24 -10 126 -15 227 -6 102 -10 199 -10 217
l0 32 -100 32 -100 31 0 14 c0 8 25 57 56 109 l55 95 -47 43 -47 43 -116 149
c-64 83 -115 152 -115 156 1 3 53 26 115 51 63 25 150 60 195 77 l81 32 41 0
42 0 0 120 0 120 22 0 c12 0 62 -10 110 -22 l89 -21 12 12 c7 6 49 69 94 139
45 70 104 162 130 204 26 43 51 76 54 75 4 -1 71 -77 149 -169 l141 -168 12 0
c7 0 23 9 36 19 l24 18 -54 64 c-30 36 -98 119 -153 186 l-98 121 -27 5 c-14
3 -33 8 -42 12z"/>
<path d="M9919 13682 l-26 17 -11 -11 -11 -11 60 -46 61 -46 87 -115 88 -115
73 -13 74 -13 18 23 c10 13 18 28 18 35 0 7 -26 55 -57 107 l-58 95 -30 0
c-16 0 -52 -4 -78 -8 l-48 -8 -67 46 c-37 25 -79 54 -93 63z"/>
<path d="M7016 2310 l-26 0 -15 -36 c-8 -20 -15 -45 -15 -56 l0 -20 21 -5 21
-6 -7 -43 -6 -43 38 -10 c21 -6 49 -11 62 -11 l24 0 -7 61 c-3 34 -6 79 -6
100 l0 38 -30 16 -29 15 -25 0z"/>
<path d="M28 1928 l-28 4 0 -172 0 -172 83 7 82 6 70 -21 c39 -12 101 -30 138
-42 l68 -20 80 4 79 3 5 -12 4 -13 57 0 56 0 44 32 c24 17 44 33 44 35 0 2
-11 26 -25 53 -14 27 -25 58 -25 69 l0 21 -32 -6 c-18 -3 -43 -7 -55 -10 l-22
-4 -82 40 -83 40 -21 0 -22 0 -57 40 -57 40 -137 37 c-75 20 -149 38 -164 41z"/>
</g>
</svg>
Alexandre

Re: Put an image svg on jpg, problem background white

Posted: 2018-11-23T22:53:42-07:00
by fmw42
This works for me with ImageMagick 6.9.10.14 Q16 Mac OSX with Inkscape 0.92.3 by adding -background none before reading the SVG image

Code: Select all

convert -background none test.svg test.png
It also works with the ImageMagick internal MSVG renderer

Code: Select all

convert -background none MSVG:test.svg test.png
And with the RSVG delegate installed

Code: Select all

convert -background none RSVG:test.svg test.png

All make the background transparent. Without the -background none, I get a white background.

See
http://us3.php.net/manual/en/imagick.se ... dcolor.php
http://us3.php.net/manual/en/imagick.se ... dcolor.php