@@ -17,13 +17,13 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('IMG_SVG')) { |
| 24 | - // complete IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP |
|
| 25 | - define('IMG_SVG', 128); |
|
| 26 | - define('IMAGETYPE_SVG', 19); |
|
| 24 | + // complete IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP |
|
| 25 | + define('IMG_SVG', 128); |
|
| 26 | + define('IMAGETYPE_SVG', 19); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -39,39 +39,39 @@ discard block |
||
| 39 | 39 | * false si on a pas pu charger l'image |
| 40 | 40 | */ |
| 41 | 41 | function svg_charger($fichier, $maxlen = null) { |
| 42 | - if (strpos($fichier, 'data:image/svg+xml') === 0) { |
|
| 43 | - $image = explode(';', $fichier, 2); |
|
| 44 | - $image = end($image); |
|
| 45 | - if (strpos($image, 'base64,') === 0) { |
|
| 46 | - $image = base64_decode(substr($image, 7)); |
|
| 47 | - } |
|
| 48 | - if (strpos($image, '<svg') !== false) { |
|
| 49 | - return $image; |
|
| 50 | - } |
|
| 51 | - // encodage inconnu ou autre format d'image ? |
|
| 52 | - return false; |
|
| 53 | - } |
|
| 54 | - // c'est peut etre deja une image svg ? |
|
| 55 | - if (strpos($fichier, '<svg') !== false) { |
|
| 56 | - return $fichier; |
|
| 57 | - } |
|
| 58 | - if (!file_exists($fichier)) { |
|
| 59 | - $fichier = supprimer_timestamp($fichier); |
|
| 60 | - if (!file_exists($fichier)) { |
|
| 61 | - return false; |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - if (is_null($maxlen)) { |
|
| 65 | - $image = file_get_contents($fichier); |
|
| 66 | - } |
|
| 67 | - else { |
|
| 68 | - $image = file_get_contents($fichier, false, null, 0, $maxlen); |
|
| 69 | - } |
|
| 70 | - // est-ce bien une image svg ? |
|
| 71 | - if (strpos($image, '<svg') !== false) { |
|
| 72 | - return $image; |
|
| 73 | - } |
|
| 74 | - return false; |
|
| 42 | + if (strpos($fichier, 'data:image/svg+xml') === 0) { |
|
| 43 | + $image = explode(';', $fichier, 2); |
|
| 44 | + $image = end($image); |
|
| 45 | + if (strpos($image, 'base64,') === 0) { |
|
| 46 | + $image = base64_decode(substr($image, 7)); |
|
| 47 | + } |
|
| 48 | + if (strpos($image, '<svg') !== false) { |
|
| 49 | + return $image; |
|
| 50 | + } |
|
| 51 | + // encodage inconnu ou autre format d'image ? |
|
| 52 | + return false; |
|
| 53 | + } |
|
| 54 | + // c'est peut etre deja une image svg ? |
|
| 55 | + if (strpos($fichier, '<svg') !== false) { |
|
| 56 | + return $fichier; |
|
| 57 | + } |
|
| 58 | + if (!file_exists($fichier)) { |
|
| 59 | + $fichier = supprimer_timestamp($fichier); |
|
| 60 | + if (!file_exists($fichier)) { |
|
| 61 | + return false; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + if (is_null($maxlen)) { |
|
| 65 | + $image = file_get_contents($fichier); |
|
| 66 | + } |
|
| 67 | + else { |
|
| 68 | + $image = file_get_contents($fichier, false, null, 0, $maxlen); |
|
| 69 | + } |
|
| 70 | + // est-ce bien une image svg ? |
|
| 71 | + if (strpos($image, '<svg') !== false) { |
|
| 72 | + return $image; |
|
| 73 | + } |
|
| 74 | + return false; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
@@ -80,28 +80,28 @@ discard block |
||
| 80 | 80 | * @return array|bool |
| 81 | 81 | */ |
| 82 | 82 | function svg_lire_balise_svg($fichier) { |
| 83 | - if (!$debut_fichier = svg_charger($fichier, 4096)) { |
|
| 84 | - return false; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - if (($ps = stripos($debut_fichier, '<svg')) !== false) { |
|
| 88 | - $pe = stripos($debut_fichier, '>', $ps); |
|
| 89 | - $balise_svg = substr($debut_fichier, $ps, $pe - $ps + 1); |
|
| 90 | - |
|
| 91 | - if (preg_match_all(',([\w:\-]+)=,Uims', $balise_svg, $matches)) { |
|
| 92 | - if (!function_exists('extraire_attribut')) { |
|
| 93 | - include_spip('inc/filtres'); |
|
| 94 | - } |
|
| 95 | - $attributs = []; |
|
| 96 | - foreach ($matches[1] as $att) { |
|
| 97 | - $attributs[$att] = extraire_attribut($balise_svg, $att); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - return [$balise_svg, $attributs]; |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - return false; |
|
| 83 | + if (!$debut_fichier = svg_charger($fichier, 4096)) { |
|
| 84 | + return false; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + if (($ps = stripos($debut_fichier, '<svg')) !== false) { |
|
| 88 | + $pe = stripos($debut_fichier, '>', $ps); |
|
| 89 | + $balise_svg = substr($debut_fichier, $ps, $pe - $ps + 1); |
|
| 90 | + |
|
| 91 | + if (preg_match_all(',([\w:\-]+)=,Uims', $balise_svg, $matches)) { |
|
| 92 | + if (!function_exists('extraire_attribut')) { |
|
| 93 | + include_spip('inc/filtres'); |
|
| 94 | + } |
|
| 95 | + $attributs = []; |
|
| 96 | + foreach ($matches[1] as $att) { |
|
| 97 | + $attributs[$att] = extraire_attribut($balise_svg, $att); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + return [$balise_svg, $attributs]; |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + return false; |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
@@ -111,12 +111,12 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | function svg_lire_attributs($img) { |
| 113 | 113 | |
| 114 | - if ($svg_infos = svg_lire_balise_svg($img)) { |
|
| 115 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 116 | - return $attributs; |
|
| 117 | - } |
|
| 114 | + if ($svg_infos = svg_lire_balise_svg($img)) { |
|
| 115 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 116 | + return $attributs; |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - return false; |
|
| 119 | + return false; |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -126,38 +126,38 @@ discard block |
||
| 126 | 126 | * @return bool|float|int |
| 127 | 127 | */ |
| 128 | 128 | function svg_dimension_to_pixels($dimension, $precision = 2) { |
| 129 | - if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)) { |
|
| 130 | - switch (strtolower($m[2])) { |
|
| 131 | - case '%': |
|
| 132 | - // on ne sait pas faire :( |
|
| 133 | - return false; |
|
| 134 | - break; |
|
| 135 | - case 'em': |
|
| 136 | - return round($m[1] * 16, $precision); // 16px font-size par defaut |
|
| 137 | - break; |
|
| 138 | - case 'ex': |
|
| 139 | - return round($m[1] * 16, $precision); // 16px font-size par defaut |
|
| 140 | - break; |
|
| 141 | - case 'pc': |
|
| 142 | - return round($m[1] * 16, $precision); // 1/6 inch = 96px/6 in CSS |
|
| 143 | - break; |
|
| 144 | - case 'cm': |
|
| 145 | - return round($m[1] * 96 / 2.54, $precision); // 96px / 2.54cm; |
|
| 146 | - break; |
|
| 147 | - case 'mm': |
|
| 148 | - return round($m[1] * 96 / 25.4, $precision); // 96px / 25.4mm; |
|
| 149 | - break; |
|
| 150 | - case 'in': |
|
| 151 | - return round($m[1] * 96, $precision); // 1 inch = 96px in CSS |
|
| 152 | - break; |
|
| 153 | - case 'px': |
|
| 154 | - case 'pt': |
|
| 155 | - default: |
|
| 156 | - return $m[1]; |
|
| 157 | - break; |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - return false; |
|
| 129 | + if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)) { |
|
| 130 | + switch (strtolower($m[2])) { |
|
| 131 | + case '%': |
|
| 132 | + // on ne sait pas faire :( |
|
| 133 | + return false; |
|
| 134 | + break; |
|
| 135 | + case 'em': |
|
| 136 | + return round($m[1] * 16, $precision); // 16px font-size par defaut |
|
| 137 | + break; |
|
| 138 | + case 'ex': |
|
| 139 | + return round($m[1] * 16, $precision); // 16px font-size par defaut |
|
| 140 | + break; |
|
| 141 | + case 'pc': |
|
| 142 | + return round($m[1] * 16, $precision); // 1/6 inch = 96px/6 in CSS |
|
| 143 | + break; |
|
| 144 | + case 'cm': |
|
| 145 | + return round($m[1] * 96 / 2.54, $precision); // 96px / 2.54cm; |
|
| 146 | + break; |
|
| 147 | + case 'mm': |
|
| 148 | + return round($m[1] * 96 / 25.4, $precision); // 96px / 25.4mm; |
|
| 149 | + break; |
|
| 150 | + case 'in': |
|
| 151 | + return round($m[1] * 96, $precision); // 1 inch = 96px in CSS |
|
| 152 | + break; |
|
| 153 | + case 'px': |
|
| 154 | + case 'pt': |
|
| 155 | + default: |
|
| 156 | + return $m[1]; |
|
| 157 | + break; |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + return false; |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** |
@@ -168,15 +168,15 @@ discard block |
||
| 168 | 168 | * @return string |
| 169 | 169 | */ |
| 170 | 170 | function svg_change_balise_svg($svg, $old_balise_svg, $attributs) { |
| 171 | - $new_balise_svg = '<svg'; |
|
| 172 | - foreach ($attributs as $k => $v) { |
|
| 173 | - $new_balise_svg .= " $k=\"" . entites_html($v) . '"'; |
|
| 174 | - } |
|
| 175 | - $new_balise_svg .= '>'; |
|
| 176 | - |
|
| 177 | - $p = strpos($svg, $old_balise_svg); |
|
| 178 | - $svg = substr_replace($svg, $new_balise_svg, $p, strlen($old_balise_svg)); |
|
| 179 | - return $svg; |
|
| 171 | + $new_balise_svg = '<svg'; |
|
| 172 | + foreach ($attributs as $k => $v) { |
|
| 173 | + $new_balise_svg .= " $k=\"" . entites_html($v) . '"'; |
|
| 174 | + } |
|
| 175 | + $new_balise_svg .= '>'; |
|
| 176 | + |
|
| 177 | + $p = strpos($svg, $old_balise_svg); |
|
| 178 | + $svg = substr_replace($svg, $new_balise_svg, $p, strlen($old_balise_svg)); |
|
| 179 | + return $svg; |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | /** |
@@ -188,15 +188,15 @@ discard block |
||
| 188 | 188 | */ |
| 189 | 189 | function svg_insert_shapes($svg, $shapes, $start = true) { |
| 190 | 190 | |
| 191 | - if ($start === false or $start === 'end') { |
|
| 192 | - $svg = str_replace('</svg>', $shapes . '</svg>', $svg); |
|
| 193 | - } |
|
| 194 | - else { |
|
| 195 | - $p = stripos($svg, '<svg'); |
|
| 196 | - $p = strpos($svg, '>', $p); |
|
| 197 | - $svg = substr_replace($svg, $shapes, $p + 1, 0); |
|
| 198 | - } |
|
| 199 | - return $svg; |
|
| 191 | + if ($start === false or $start === 'end') { |
|
| 192 | + $svg = str_replace('</svg>', $shapes . '</svg>', $svg); |
|
| 193 | + } |
|
| 194 | + else { |
|
| 195 | + $p = stripos($svg, '<svg'); |
|
| 196 | + $p = strpos($svg, '>', $p); |
|
| 197 | + $svg = substr_replace($svg, $shapes, $p + 1, 0); |
|
| 198 | + } |
|
| 199 | + return $svg; |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | /** |
@@ -209,13 +209,13 @@ discard block |
||
| 209 | 209 | * @return string |
| 210 | 210 | */ |
| 211 | 211 | function svg_clip_in_box($svg, $x, $y, $width, $height) { |
| 212 | - $rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />"; |
|
| 213 | - $id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8); |
|
| 214 | - $clippath = "<clipPath id=\"$id\">$rect</clipPath>"; |
|
| 215 | - $g = "<g clip-path=\"url(#$id)\">"; |
|
| 216 | - $svg = svg_insert_shapes($svg, $clippath . $g); |
|
| 217 | - $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 218 | - return $svg; |
|
| 212 | + $rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />"; |
|
| 213 | + $id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8); |
|
| 214 | + $clippath = "<clipPath id=\"$id\">$rect</clipPath>"; |
|
| 215 | + $g = "<g clip-path=\"url(#$id)\">"; |
|
| 216 | + $svg = svg_insert_shapes($svg, $clippath . $g); |
|
| 217 | + $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 218 | + return $svg; |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | /** |
@@ -226,22 +226,22 @@ discard block |
||
| 226 | 226 | * @return bool|string |
| 227 | 227 | */ |
| 228 | 228 | function svg_redimensionner($img, $new_width, $new_height) { |
| 229 | - if ( |
|
| 230 | - $svg = svg_charger($img) |
|
| 231 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 232 | - ) { |
|
| 233 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 234 | - if (!isset($attributs['viewBox'])) { |
|
| 235 | - $attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height']; |
|
| 236 | - } |
|
| 237 | - $attributs['width'] = strval($new_width); |
|
| 238 | - $attributs['height'] = strval($new_height); |
|
| 239 | - |
|
| 240 | - $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 241 | - return $svg; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - return $img; |
|
| 229 | + if ( |
|
| 230 | + $svg = svg_charger($img) |
|
| 231 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 232 | + ) { |
|
| 233 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 234 | + if (!isset($attributs['viewBox'])) { |
|
| 235 | + $attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height']; |
|
| 236 | + } |
|
| 237 | + $attributs['width'] = strval($new_width); |
|
| 238 | + $attributs['height'] = strval($new_height); |
|
| 239 | + |
|
| 240 | + $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 241 | + return $svg; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + return $img; |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | /** |
@@ -250,15 +250,15 @@ discard block |
||
| 250 | 250 | * @return string |
| 251 | 251 | */ |
| 252 | 252 | function svg_couleur_to_hexa($couleur) { |
| 253 | - if (strpos($couleur, 'rgb(') === 0) { |
|
| 254 | - $c = explode(',', substr($couleur, 4)); |
|
| 255 | - $couleur = _couleur_dec_to_hex(intval($c[0]), intval($c[1]), intval($c[2])); |
|
| 256 | - } |
|
| 257 | - else { |
|
| 258 | - $couleur = couleur_html_to_hex($couleur); |
|
| 259 | - } |
|
| 260 | - $couleur = '#' . ltrim($couleur, '#'); |
|
| 261 | - return $couleur; |
|
| 253 | + if (strpos($couleur, 'rgb(') === 0) { |
|
| 254 | + $c = explode(',', substr($couleur, 4)); |
|
| 255 | + $couleur = _couleur_dec_to_hex(intval($c[0]), intval($c[1]), intval($c[2])); |
|
| 256 | + } |
|
| 257 | + else { |
|
| 258 | + $couleur = couleur_html_to_hex($couleur); |
|
| 259 | + } |
|
| 260 | + $couleur = '#' . ltrim($couleur, '#'); |
|
| 261 | + return $couleur; |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
@@ -267,11 +267,11 @@ discard block |
||
| 267 | 267 | * @return array |
| 268 | 268 | */ |
| 269 | 269 | function svg_couleur_to_rgb($couleur) { |
| 270 | - if (strpos($couleur, 'rgb(') === 0) { |
|
| 271 | - $c = explode(',', substr($couleur, 4)); |
|
| 272 | - return ['red' => intval($c[0]),'green' => intval($c[1]),'blue' => intval($c[2])]; |
|
| 273 | - } |
|
| 274 | - return _couleur_hex_to_dec($couleur); |
|
| 270 | + if (strpos($couleur, 'rgb(') === 0) { |
|
| 271 | + $c = explode(',', substr($couleur, 4)); |
|
| 272 | + return ['red' => intval($c[0]),'green' => intval($c[1]),'blue' => intval($c[2])]; |
|
| 273 | + } |
|
| 274 | + return _couleur_hex_to_dec($couleur); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | |
@@ -281,80 +281,80 @@ discard block |
||
| 281 | 281 | * @return array |
| 282 | 282 | */ |
| 283 | 283 | function svg_getimagesize_from_attr($attributs) { |
| 284 | - $width = 350; // default width |
|
| 285 | - $height = 150; // default height |
|
| 286 | - |
|
| 287 | - $viewBox = "0 0 $width $height"; |
|
| 288 | - if (isset($attributs['viewBox'])) { |
|
| 289 | - $viewBox = $attributs['viewBox']; |
|
| 290 | - $viewBox = preg_replace(',\s+,', ' ', $viewBox); |
|
| 291 | - } |
|
| 292 | - // et on la convertit en px |
|
| 293 | - $viewBox = explode(' ', $viewBox); |
|
| 294 | - $viewBox = array_map('svg_dimension_to_pixels', $viewBox); |
|
| 295 | - if (!$viewBox[2]) { |
|
| 296 | - $viewBox[2] = $width; |
|
| 297 | - } |
|
| 298 | - if (!$viewBox[3]) { |
|
| 299 | - $viewBox[3] = $height; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - $coeff = 1; |
|
| 303 | - if ( |
|
| 304 | - isset($attributs['width']) |
|
| 305 | - and $w = svg_dimension_to_pixels($attributs['width']) |
|
| 306 | - ) { |
|
| 307 | - $width = $w; |
|
| 308 | - // si on avait pas de viewBox, la construire a partir de ce width |
|
| 309 | - if (empty($attributs['viewBox'])) { |
|
| 310 | - $viewBox[2] = $width; |
|
| 311 | - // si pas de height valide, on suppose l'image carree |
|
| 312 | - $viewBox[3] = $width; |
|
| 313 | - } |
|
| 314 | - } |
|
| 315 | - else { |
|
| 316 | - // si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale |
|
| 317 | - $width = $viewBox[2]; |
|
| 318 | - if ($width < 1) { |
|
| 319 | - $coeff = max($coeff, 1000); |
|
| 320 | - } |
|
| 321 | - elseif ($width < 10) { |
|
| 322 | - $coeff = max($coeff, 100); |
|
| 323 | - } |
|
| 324 | - elseif ($width < 100) { |
|
| 325 | - $coeff = max($coeff, 10); |
|
| 326 | - } |
|
| 327 | - } |
|
| 328 | - if ( |
|
| 329 | - isset($attributs['height']) |
|
| 330 | - and $h = svg_dimension_to_pixels($attributs['height']) |
|
| 331 | - ) { |
|
| 332 | - $height = $h; |
|
| 333 | - // si on avait pas de viewBox, la construire a partir de ce height |
|
| 334 | - if (empty($attributs['viewBox'])) { |
|
| 335 | - $viewBox[3] = $height; |
|
| 336 | - } |
|
| 337 | - } |
|
| 338 | - else { |
|
| 339 | - $height = $viewBox[3]; |
|
| 340 | - if ($height < 1) { |
|
| 341 | - $coeff = max($coeff, 1000); |
|
| 342 | - } |
|
| 343 | - elseif ($height < 10) { |
|
| 344 | - $coeff = max($coeff, 100); |
|
| 345 | - } |
|
| 346 | - elseif ($height < 100) { |
|
| 347 | - $coeff = max($coeff, 10); |
|
| 348 | - } |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - // arrondir le width et height en pixel in fine |
|
| 352 | - $width = round($coeff * $width); |
|
| 353 | - $height = round($coeff * $height); |
|
| 354 | - |
|
| 355 | - $viewBox = implode(' ', $viewBox); |
|
| 356 | - |
|
| 357 | - return [$width, $height, $viewBox]; |
|
| 284 | + $width = 350; // default width |
|
| 285 | + $height = 150; // default height |
|
| 286 | + |
|
| 287 | + $viewBox = "0 0 $width $height"; |
|
| 288 | + if (isset($attributs['viewBox'])) { |
|
| 289 | + $viewBox = $attributs['viewBox']; |
|
| 290 | + $viewBox = preg_replace(',\s+,', ' ', $viewBox); |
|
| 291 | + } |
|
| 292 | + // et on la convertit en px |
|
| 293 | + $viewBox = explode(' ', $viewBox); |
|
| 294 | + $viewBox = array_map('svg_dimension_to_pixels', $viewBox); |
|
| 295 | + if (!$viewBox[2]) { |
|
| 296 | + $viewBox[2] = $width; |
|
| 297 | + } |
|
| 298 | + if (!$viewBox[3]) { |
|
| 299 | + $viewBox[3] = $height; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + $coeff = 1; |
|
| 303 | + if ( |
|
| 304 | + isset($attributs['width']) |
|
| 305 | + and $w = svg_dimension_to_pixels($attributs['width']) |
|
| 306 | + ) { |
|
| 307 | + $width = $w; |
|
| 308 | + // si on avait pas de viewBox, la construire a partir de ce width |
|
| 309 | + if (empty($attributs['viewBox'])) { |
|
| 310 | + $viewBox[2] = $width; |
|
| 311 | + // si pas de height valide, on suppose l'image carree |
|
| 312 | + $viewBox[3] = $width; |
|
| 313 | + } |
|
| 314 | + } |
|
| 315 | + else { |
|
| 316 | + // si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale |
|
| 317 | + $width = $viewBox[2]; |
|
| 318 | + if ($width < 1) { |
|
| 319 | + $coeff = max($coeff, 1000); |
|
| 320 | + } |
|
| 321 | + elseif ($width < 10) { |
|
| 322 | + $coeff = max($coeff, 100); |
|
| 323 | + } |
|
| 324 | + elseif ($width < 100) { |
|
| 325 | + $coeff = max($coeff, 10); |
|
| 326 | + } |
|
| 327 | + } |
|
| 328 | + if ( |
|
| 329 | + isset($attributs['height']) |
|
| 330 | + and $h = svg_dimension_to_pixels($attributs['height']) |
|
| 331 | + ) { |
|
| 332 | + $height = $h; |
|
| 333 | + // si on avait pas de viewBox, la construire a partir de ce height |
|
| 334 | + if (empty($attributs['viewBox'])) { |
|
| 335 | + $viewBox[3] = $height; |
|
| 336 | + } |
|
| 337 | + } |
|
| 338 | + else { |
|
| 339 | + $height = $viewBox[3]; |
|
| 340 | + if ($height < 1) { |
|
| 341 | + $coeff = max($coeff, 1000); |
|
| 342 | + } |
|
| 343 | + elseif ($height < 10) { |
|
| 344 | + $coeff = max($coeff, 100); |
|
| 345 | + } |
|
| 346 | + elseif ($height < 100) { |
|
| 347 | + $coeff = max($coeff, 10); |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + // arrondir le width et height en pixel in fine |
|
| 352 | + $width = round($coeff * $width); |
|
| 353 | + $height = round($coeff * $height); |
|
| 354 | + |
|
| 355 | + $viewBox = implode(' ', $viewBox); |
|
| 356 | + |
|
| 357 | + return [$width, $height, $viewBox]; |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | /** |
@@ -370,25 +370,25 @@ discard block |
||
| 370 | 370 | * @return string |
| 371 | 371 | */ |
| 372 | 372 | function svg_force_viewBox_px($img, $force_width_and_height = false) { |
| 373 | - if ( |
|
| 374 | - $svg = svg_charger($img) |
|
| 375 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 376 | - ) { |
|
| 377 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 373 | + if ( |
|
| 374 | + $svg = svg_charger($img) |
|
| 375 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 376 | + ) { |
|
| 377 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 378 | 378 | |
| 379 | - [$width, $height, $viewBox] = svg_getimagesize_from_attr($attributs); |
|
| 379 | + [$width, $height, $viewBox] = svg_getimagesize_from_attr($attributs); |
|
| 380 | 380 | |
| 381 | - if ($force_width_and_height) { |
|
| 382 | - $attributs['width'] = $width; |
|
| 383 | - $attributs['height'] = $height; |
|
| 384 | - } |
|
| 381 | + if ($force_width_and_height) { |
|
| 382 | + $attributs['width'] = $width; |
|
| 383 | + $attributs['height'] = $height; |
|
| 384 | + } |
|
| 385 | 385 | |
| 386 | - $attributs['viewBox'] = $viewBox; |
|
| 386 | + $attributs['viewBox'] = $viewBox; |
|
| 387 | 387 | |
| 388 | - $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 389 | - return $svg; |
|
| 390 | - } |
|
| 391 | - return $img; |
|
| 388 | + $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 389 | + return $svg; |
|
| 390 | + } |
|
| 391 | + return $img; |
|
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | /** |
@@ -397,12 +397,12 @@ discard block |
||
| 397 | 397 | * @return array|mixed |
| 398 | 398 | */ |
| 399 | 399 | function svg_extract_couleurs($img) { |
| 400 | - if ($svg = svg_charger($img)) { |
|
| 401 | - if (preg_match_all('/(#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])|(rgb\([\s\d]+,[\s\d]+,[\s\d]+\))|(#[0-9a-f][0-9a-f][0-9a-f])/imS', $svg, $matches)) { |
|
| 402 | - return $matches[0]; |
|
| 403 | - } |
|
| 404 | - } |
|
| 405 | - return []; |
|
| 400 | + if ($svg = svg_charger($img)) { |
|
| 401 | + if (preg_match_all('/(#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])|(rgb\([\s\d]+,[\s\d]+,[\s\d]+\))|(#[0-9a-f][0-9a-f][0-9a-f])/imS', $svg, $matches)) { |
|
| 402 | + return $matches[0]; |
|
| 403 | + } |
|
| 404 | + } |
|
| 405 | + return []; |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | /** |
@@ -413,58 +413,58 @@ discard block |
||
| 413 | 413 | * @return bool|string |
| 414 | 414 | */ |
| 415 | 415 | function svg_recadrer($img, $new_width, $new_height, $offset_width, $offset_height, $background_color = '') { |
| 416 | - if ( |
|
| 417 | - $svg = svg_force_viewBox_px($img) |
|
| 418 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 419 | - ) { |
|
| 420 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 421 | - $viewBox = explode(' ', $attributs['viewBox']); |
|
| 422 | - |
|
| 423 | - $viewport_w = $new_width; |
|
| 424 | - $viewport_h = $new_height; |
|
| 425 | - $viewport_ox = $offset_width; |
|
| 426 | - $viewport_oy = $offset_height; |
|
| 427 | - |
|
| 428 | - // si on a un width/height qui rescale, il faut rescaler |
|
| 429 | - if ( |
|
| 430 | - isset($attributs['width']) |
|
| 431 | - and $w = svg_dimension_to_pixels($attributs['width']) |
|
| 432 | - and isset($attributs['height']) |
|
| 433 | - and $h = svg_dimension_to_pixels($attributs['height']) |
|
| 434 | - ) { |
|
| 435 | - $xscale = $viewBox[2] / $w; |
|
| 436 | - $viewport_w = round($viewport_w * $xscale, 2); |
|
| 437 | - $viewport_ox = round($viewport_ox * $xscale, 2); |
|
| 438 | - $yscale = $viewBox[3] / $h; |
|
| 439 | - $viewport_h = round($viewport_h * $yscale, 2); |
|
| 440 | - $viewport_oy = round($viewport_oy * $yscale, 2); |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - if ($viewport_w > $viewBox[2] or $viewport_h > $viewBox[3]) { |
|
| 444 | - $svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]); |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - // maintenant on redefinit la viewBox |
|
| 448 | - $viewBox[0] += $viewport_ox; |
|
| 449 | - $viewBox[1] += $viewport_oy; |
|
| 450 | - $viewBox[2] = $viewport_w; |
|
| 451 | - $viewBox[3] = $viewport_h; |
|
| 452 | - |
|
| 453 | - $attributs['viewBox'] = implode(' ', $viewBox); |
|
| 454 | - $attributs['width'] = strval($new_width); |
|
| 455 | - $attributs['height'] = strval($new_height); |
|
| 456 | - |
|
| 457 | - $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 458 | - |
|
| 459 | - // ajouter un background |
|
| 460 | - if ($background_color and $background_color !== 'transparent') { |
|
| 461 | - $svg = svg_ajouter_background($svg, $background_color); |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - return $svg; |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - return $img; |
|
| 416 | + if ( |
|
| 417 | + $svg = svg_force_viewBox_px($img) |
|
| 418 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 419 | + ) { |
|
| 420 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 421 | + $viewBox = explode(' ', $attributs['viewBox']); |
|
| 422 | + |
|
| 423 | + $viewport_w = $new_width; |
|
| 424 | + $viewport_h = $new_height; |
|
| 425 | + $viewport_ox = $offset_width; |
|
| 426 | + $viewport_oy = $offset_height; |
|
| 427 | + |
|
| 428 | + // si on a un width/height qui rescale, il faut rescaler |
|
| 429 | + if ( |
|
| 430 | + isset($attributs['width']) |
|
| 431 | + and $w = svg_dimension_to_pixels($attributs['width']) |
|
| 432 | + and isset($attributs['height']) |
|
| 433 | + and $h = svg_dimension_to_pixels($attributs['height']) |
|
| 434 | + ) { |
|
| 435 | + $xscale = $viewBox[2] / $w; |
|
| 436 | + $viewport_w = round($viewport_w * $xscale, 2); |
|
| 437 | + $viewport_ox = round($viewport_ox * $xscale, 2); |
|
| 438 | + $yscale = $viewBox[3] / $h; |
|
| 439 | + $viewport_h = round($viewport_h * $yscale, 2); |
|
| 440 | + $viewport_oy = round($viewport_oy * $yscale, 2); |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + if ($viewport_w > $viewBox[2] or $viewport_h > $viewBox[3]) { |
|
| 444 | + $svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]); |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + // maintenant on redefinit la viewBox |
|
| 448 | + $viewBox[0] += $viewport_ox; |
|
| 449 | + $viewBox[1] += $viewport_oy; |
|
| 450 | + $viewBox[2] = $viewport_w; |
|
| 451 | + $viewBox[3] = $viewport_h; |
|
| 452 | + |
|
| 453 | + $attributs['viewBox'] = implode(' ', $viewBox); |
|
| 454 | + $attributs['width'] = strval($new_width); |
|
| 455 | + $attributs['height'] = strval($new_height); |
|
| 456 | + |
|
| 457 | + $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 458 | + |
|
| 459 | + // ajouter un background |
|
| 460 | + if ($background_color and $background_color !== 'transparent') { |
|
| 461 | + $svg = svg_ajouter_background($svg, $background_color); |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + return $svg; |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + return $img; |
|
| 468 | 468 | } |
| 469 | 469 | |
| 470 | 470 | /** |
@@ -474,26 +474,26 @@ discard block |
||
| 474 | 474 | * @return bool|string |
| 475 | 475 | */ |
| 476 | 476 | function svg_ajouter_background($img, $background_color) { |
| 477 | - if ( |
|
| 478 | - $svg = svg_charger($img) |
|
| 479 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 480 | - ) { |
|
| 481 | - if ($background_color and $background_color !== 'transparent') { |
|
| 482 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 483 | - |
|
| 484 | - $background_color = svg_couleur_to_hexa($background_color); |
|
| 485 | - if (isset($attributs['viewBox'])) { |
|
| 486 | - $viewBox = explode(' ', $attributs['viewBox']); |
|
| 487 | - $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>"; |
|
| 488 | - } |
|
| 489 | - else { |
|
| 490 | - $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 491 | - } |
|
| 492 | - $svg = svg_insert_shapes($svg, $rect); |
|
| 493 | - } |
|
| 494 | - return $svg; |
|
| 495 | - } |
|
| 496 | - return $img; |
|
| 477 | + if ( |
|
| 478 | + $svg = svg_charger($img) |
|
| 479 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 480 | + ) { |
|
| 481 | + if ($background_color and $background_color !== 'transparent') { |
|
| 482 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 483 | + |
|
| 484 | + $background_color = svg_couleur_to_hexa($background_color); |
|
| 485 | + if (isset($attributs['viewBox'])) { |
|
| 486 | + $viewBox = explode(' ', $attributs['viewBox']); |
|
| 487 | + $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>"; |
|
| 488 | + } |
|
| 489 | + else { |
|
| 490 | + $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 491 | + } |
|
| 492 | + $svg = svg_insert_shapes($svg, $rect); |
|
| 493 | + } |
|
| 494 | + return $svg; |
|
| 495 | + } |
|
| 496 | + return $img; |
|
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | |
@@ -504,26 +504,26 @@ discard block |
||
| 504 | 504 | * @return bool|string |
| 505 | 505 | */ |
| 506 | 506 | function svg_ajouter_voile($img, $background_color, $opacity) { |
| 507 | - if ( |
|
| 508 | - $svg = svg_charger($img) |
|
| 509 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 510 | - ) { |
|
| 511 | - if ($background_color and $background_color !== 'transparent') { |
|
| 512 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 513 | - |
|
| 514 | - $background_color = svg_couleur_to_hexa($background_color); |
|
| 515 | - if (isset($attributs['viewBox'])) { |
|
| 516 | - $viewBox = explode(' ', $attributs['viewBox']); |
|
| 517 | - $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>"; |
|
| 518 | - } |
|
| 519 | - else { |
|
| 520 | - $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 521 | - } |
|
| 522 | - $svg = svg_insert_shapes($svg, $rect, false); |
|
| 523 | - } |
|
| 524 | - return $svg; |
|
| 525 | - } |
|
| 526 | - return $img; |
|
| 507 | + if ( |
|
| 508 | + $svg = svg_charger($img) |
|
| 509 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 510 | + ) { |
|
| 511 | + if ($background_color and $background_color !== 'transparent') { |
|
| 512 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 513 | + |
|
| 514 | + $background_color = svg_couleur_to_hexa($background_color); |
|
| 515 | + if (isset($attributs['viewBox'])) { |
|
| 516 | + $viewBox = explode(' ', $attributs['viewBox']); |
|
| 517 | + $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>"; |
|
| 518 | + } |
|
| 519 | + else { |
|
| 520 | + $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 521 | + } |
|
| 522 | + $svg = svg_insert_shapes($svg, $rect, false); |
|
| 523 | + } |
|
| 524 | + return $svg; |
|
| 525 | + } |
|
| 526 | + return $img; |
|
| 527 | 527 | } |
| 528 | 528 | |
| 529 | 529 | |
@@ -534,27 +534,27 @@ discard block |
||
| 534 | 534 | * @return bool|string |
| 535 | 535 | */ |
| 536 | 536 | function svg_transformer($img, $attributs) { |
| 537 | - if ( |
|
| 538 | - $svg = svg_charger($img) |
|
| 539 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 540 | - ) { |
|
| 541 | - if ($attributs) { |
|
| 542 | - [$balise_svg, ] = $svg_infos; |
|
| 543 | - $g = '<g'; |
|
| 544 | - foreach ($attributs as $k => $v) { |
|
| 545 | - if (strlen($v)) { |
|
| 546 | - $g .= " $k=\"" . attribut_html($v) . '"'; |
|
| 547 | - } |
|
| 548 | - } |
|
| 549 | - if (strlen($g) > 2) { |
|
| 550 | - $g .= '>'; |
|
| 551 | - $svg = svg_insert_shapes($svg, $g); |
|
| 552 | - $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 553 | - } |
|
| 554 | - } |
|
| 555 | - return $svg; |
|
| 556 | - } |
|
| 557 | - return $img; |
|
| 537 | + if ( |
|
| 538 | + $svg = svg_charger($img) |
|
| 539 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 540 | + ) { |
|
| 541 | + if ($attributs) { |
|
| 542 | + [$balise_svg, ] = $svg_infos; |
|
| 543 | + $g = '<g'; |
|
| 544 | + foreach ($attributs as $k => $v) { |
|
| 545 | + if (strlen($v)) { |
|
| 546 | + $g .= " $k=\"" . attribut_html($v) . '"'; |
|
| 547 | + } |
|
| 548 | + } |
|
| 549 | + if (strlen($g) > 2) { |
|
| 550 | + $g .= '>'; |
|
| 551 | + $svg = svg_insert_shapes($svg, $g); |
|
| 552 | + $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 553 | + } |
|
| 554 | + } |
|
| 555 | + return $svg; |
|
| 556 | + } |
|
| 557 | + return $img; |
|
| 558 | 558 | } |
| 559 | 559 | |
| 560 | 560 | /** |
@@ -565,21 +565,21 @@ discard block |
||
| 565 | 565 | * @return bool|string |
| 566 | 566 | */ |
| 567 | 567 | function svg_apply_filter($img, $filter_def) { |
| 568 | - if ( |
|
| 569 | - $svg = svg_charger($img) |
|
| 570 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 571 | - ) { |
|
| 572 | - if ($filter_def) { |
|
| 573 | - [$balise_svg, ] = $svg_infos; |
|
| 574 | - $filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8); |
|
| 575 | - $filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>"; |
|
| 576 | - $g = "<g filter=\"url(#$filter_id)\">"; |
|
| 577 | - $svg = svg_insert_shapes($svg, $filter . $g); |
|
| 578 | - $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 579 | - } |
|
| 580 | - return $svg; |
|
| 581 | - } |
|
| 582 | - return $img; |
|
| 568 | + if ( |
|
| 569 | + $svg = svg_charger($img) |
|
| 570 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 571 | + ) { |
|
| 572 | + if ($filter_def) { |
|
| 573 | + [$balise_svg, ] = $svg_infos; |
|
| 574 | + $filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8); |
|
| 575 | + $filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>"; |
|
| 576 | + $g = "<g filter=\"url(#$filter_id)\">"; |
|
| 577 | + $svg = svg_insert_shapes($svg, $filter . $g); |
|
| 578 | + $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 579 | + } |
|
| 580 | + return $svg; |
|
| 581 | + } |
|
| 582 | + return $img; |
|
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | /** |
@@ -589,8 +589,8 @@ discard block |
||
| 589 | 589 | * @return string |
| 590 | 590 | */ |
| 591 | 591 | function svg_filter_blur($img, $blur_width) { |
| 592 | - $blur_width = intval($blur_width); |
|
| 593 | - return svg_apply_filter($img, "<feGaussianBlur stdDeviation=\"$blur_width\"/>"); |
|
| 592 | + $blur_width = intval($blur_width); |
|
| 593 | + return svg_apply_filter($img, "<feGaussianBlur stdDeviation=\"$blur_width\"/>"); |
|
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | /** |
@@ -600,10 +600,10 @@ discard block |
||
| 600 | 600 | * @return bool|string |
| 601 | 601 | */ |
| 602 | 602 | function svg_filter_grayscale($img, $intensity) { |
| 603 | - $value = round(1.0 - $intensity, 2); |
|
| 604 | - //$filter = "<feColorMatrix type=\"matrix\" values=\"0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\"/>"; |
|
| 605 | - $filter = "<feColorMatrix type=\"saturate\" values=\"$value\"/>"; |
|
| 606 | - return svg_apply_filter($img, $filter); |
|
| 603 | + $value = round(1.0 - $intensity, 2); |
|
| 604 | + //$filter = "<feColorMatrix type=\"matrix\" values=\"0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\"/>"; |
|
| 605 | + $filter = "<feColorMatrix type=\"saturate\" values=\"$value\"/>"; |
|
| 606 | + return svg_apply_filter($img, $filter); |
|
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | /** |
@@ -613,8 +613,8 @@ discard block |
||
| 613 | 613 | * @return bool|string |
| 614 | 614 | */ |
| 615 | 615 | function svg_filter_sepia($img, $intensity) { |
| 616 | - $filter = '<feColorMatrix type="matrix" values="0.30 0.30 0.30 0.0 0 0.25 0.25 0.25 0.0 0 0.20 0.20 0.20 0.0 0 0.00 0.00 0.00 1 0"/>'; |
|
| 617 | - return svg_apply_filter($img, $filter); |
|
| 616 | + $filter = '<feColorMatrix type="matrix" values="0.30 0.30 0.30 0.0 0 0.25 0.25 0.25 0.0 0 0.20 0.20 0.20 0.0 0 0.00 0.00 0.00 1 0"/>'; |
|
| 617 | + return svg_apply_filter($img, $filter); |
|
| 618 | 618 | } |
| 619 | 619 | |
| 620 | 620 | /** |
@@ -624,31 +624,31 @@ discard block |
||
| 624 | 624 | * @return bool|string |
| 625 | 625 | */ |
| 626 | 626 | function svg_flip($img, $HorV) { |
| 627 | - if ( |
|
| 628 | - $svg = svg_force_viewBox_px($img) |
|
| 629 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 630 | - ) { |
|
| 631 | - [$balise_svg, $atts] = $svg_infos; |
|
| 632 | - $viewBox = explode(' ', $atts['viewBox']); |
|
| 633 | - |
|
| 634 | - if (!in_array($HorV, ['h', 'H'])) { |
|
| 635 | - $transform = 'scale(-1,1)'; |
|
| 636 | - |
|
| 637 | - $x = intval($viewBox[0]) + intval($viewBox[2] / 2); |
|
| 638 | - $mx = -$x; |
|
| 639 | - $transform = "translate($x, 0) $transform translate($mx, 0)"; |
|
| 640 | - } |
|
| 641 | - else { |
|
| 642 | - $transform = 'scale(1,-1)'; |
|
| 643 | - |
|
| 644 | - $y = intval($viewBox[1]) + intval($viewBox[3] / 2); |
|
| 645 | - $my = -$y; |
|
| 646 | - $transform = "translate(0, $y) $transform translate(0, $my)"; |
|
| 647 | - } |
|
| 648 | - $svg = svg_transformer($svg, ['transform' => $transform]); |
|
| 649 | - return $svg; |
|
| 650 | - } |
|
| 651 | - return $img; |
|
| 627 | + if ( |
|
| 628 | + $svg = svg_force_viewBox_px($img) |
|
| 629 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 630 | + ) { |
|
| 631 | + [$balise_svg, $atts] = $svg_infos; |
|
| 632 | + $viewBox = explode(' ', $atts['viewBox']); |
|
| 633 | + |
|
| 634 | + if (!in_array($HorV, ['h', 'H'])) { |
|
| 635 | + $transform = 'scale(-1,1)'; |
|
| 636 | + |
|
| 637 | + $x = intval($viewBox[0]) + intval($viewBox[2] / 2); |
|
| 638 | + $mx = -$x; |
|
| 639 | + $transform = "translate($x, 0) $transform translate($mx, 0)"; |
|
| 640 | + } |
|
| 641 | + else { |
|
| 642 | + $transform = 'scale(1,-1)'; |
|
| 643 | + |
|
| 644 | + $y = intval($viewBox[1]) + intval($viewBox[3] / 2); |
|
| 645 | + $my = -$y; |
|
| 646 | + $transform = "translate(0, $y) $transform translate(0, $my)"; |
|
| 647 | + } |
|
| 648 | + $svg = svg_transformer($svg, ['transform' => $transform]); |
|
| 649 | + return $svg; |
|
| 650 | + } |
|
| 651 | + return $img; |
|
| 652 | 652 | } |
| 653 | 653 | |
| 654 | 654 | /** |
@@ -662,20 +662,20 @@ discard block |
||
| 662 | 662 | * @return bool|string |
| 663 | 663 | */ |
| 664 | 664 | function svg_rotate($img, $angle, $center_x, $center_y) { |
| 665 | - if ( |
|
| 666 | - $svg = svg_force_viewBox_px($img) |
|
| 667 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 668 | - ) { |
|
| 669 | - [$balise_svg, $atts] = $svg_infos; |
|
| 670 | - $viewBox = explode(' ', $atts['viewBox']); |
|
| 671 | - |
|
| 672 | - $center_x = round($viewBox[0] + $center_x * $viewBox[2]); |
|
| 673 | - $center_y = round($viewBox[1] + $center_y * $viewBox[3]); |
|
| 674 | - $svg = svg_transformer($svg, ['transform' => "rotate($angle $center_x $center_y)"]); |
|
| 675 | - |
|
| 676 | - return $svg; |
|
| 677 | - } |
|
| 678 | - return $img; |
|
| 665 | + if ( |
|
| 666 | + $svg = svg_force_viewBox_px($img) |
|
| 667 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 668 | + ) { |
|
| 669 | + [$balise_svg, $atts] = $svg_infos; |
|
| 670 | + $viewBox = explode(' ', $atts['viewBox']); |
|
| 671 | + |
|
| 672 | + $center_x = round($viewBox[0] + $center_x * $viewBox[2]); |
|
| 673 | + $center_y = round($viewBox[1] + $center_y * $viewBox[3]); |
|
| 674 | + $svg = svg_transformer($svg, ['transform' => "rotate($angle $center_x $center_y)"]); |
|
| 675 | + |
|
| 676 | + return $svg; |
|
| 677 | + } |
|
| 678 | + return $img; |
|
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | /** |
@@ -687,41 +687,41 @@ discard block |
||
| 687 | 687 | * @return bool|mixed|string |
| 688 | 688 | */ |
| 689 | 689 | function svg_filtrer_couleurs($img, $callback_filter) { |
| 690 | - if ( |
|
| 691 | - $svg = svg_force_viewBox_px($img) |
|
| 692 | - and $colors = svg_extract_couleurs($svg) |
|
| 693 | - ) { |
|
| 694 | - $colors = array_unique($colors); |
|
| 695 | - |
|
| 696 | - $short = []; |
|
| 697 | - $long = []; |
|
| 698 | - while (count($colors)) { |
|
| 699 | - $c = array_shift($colors); |
|
| 700 | - if (strlen($c) == 4) { |
|
| 701 | - $short[] = $c; |
|
| 702 | - } |
|
| 703 | - else { |
|
| 704 | - $long[] = $c; |
|
| 705 | - } |
|
| 706 | - } |
|
| 707 | - |
|
| 708 | - $colors = [...$long, ...$short]; |
|
| 709 | - $new_colors = []; |
|
| 710 | - $colors = array_flip($colors); |
|
| 711 | - foreach ($colors as $c => $k) { |
|
| 712 | - $colors[$c] = "@@@COLOR$$k$@@@"; |
|
| 713 | - } |
|
| 714 | - |
|
| 715 | - |
|
| 716 | - foreach ($colors as $original => $replace) { |
|
| 717 | - $new = svg_couleur_to_hexa($original); |
|
| 718 | - $new_colors[$replace] = $callback_filter($new); |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - $svg = str_replace(array_keys($colors), array_values($colors), $svg); |
|
| 722 | - $svg = str_replace(array_keys($new_colors), array_values($new_colors), $svg); |
|
| 723 | - |
|
| 724 | - return $svg; |
|
| 725 | - } |
|
| 726 | - return $img; |
|
| 690 | + if ( |
|
| 691 | + $svg = svg_force_viewBox_px($img) |
|
| 692 | + and $colors = svg_extract_couleurs($svg) |
|
| 693 | + ) { |
|
| 694 | + $colors = array_unique($colors); |
|
| 695 | + |
|
| 696 | + $short = []; |
|
| 697 | + $long = []; |
|
| 698 | + while (count($colors)) { |
|
| 699 | + $c = array_shift($colors); |
|
| 700 | + if (strlen($c) == 4) { |
|
| 701 | + $short[] = $c; |
|
| 702 | + } |
|
| 703 | + else { |
|
| 704 | + $long[] = $c; |
|
| 705 | + } |
|
| 706 | + } |
|
| 707 | + |
|
| 708 | + $colors = [...$long, ...$short]; |
|
| 709 | + $new_colors = []; |
|
| 710 | + $colors = array_flip($colors); |
|
| 711 | + foreach ($colors as $c => $k) { |
|
| 712 | + $colors[$c] = "@@@COLOR$$k$@@@"; |
|
| 713 | + } |
|
| 714 | + |
|
| 715 | + |
|
| 716 | + foreach ($colors as $original => $replace) { |
|
| 717 | + $new = svg_couleur_to_hexa($original); |
|
| 718 | + $new_colors[$replace] = $callback_filter($new); |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + $svg = str_replace(array_keys($colors), array_values($colors), $svg); |
|
| 722 | + $svg = str_replace(array_keys($new_colors), array_values($new_colors), $svg); |
|
| 723 | + |
|
| 724 | + return $svg; |
|
| 725 | + } |
|
| 726 | + return $img; |
|
| 727 | 727 | } |