@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | if (!defined('IMG_SVG')) { |
| 24 | 24 | // complete IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP |
| 25 | - define('IMG_SVG',128); |
|
| 25 | + define('IMG_SVG', 128); |
|
| 26 | 26 | define('IMAGETYPE_SVG', 19); |
| 27 | 27 | } |
| 28 | 28 | |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * @return bool|string |
| 39 | 39 | * false si on a pas pu charger l'image |
| 40 | 40 | */ |
| 41 | -function svg_charger($fichier, $maxlen=null) { |
|
| 41 | +function svg_charger($fichier, $maxlen = null) { |
|
| 42 | 42 | if (strpos($fichier, "data:image/svg+xml") === 0) { |
| 43 | 43 | $image = explode(";", $fichier, 2); |
| 44 | 44 | $image = end($image); |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | return $fichier; |
| 57 | 57 | } |
| 58 | 58 | if (!file_exists($fichier)) { |
| 59 | - $fichier = supprimer_timestamp($fichier); |
|
| 59 | + $fichier = supprimer_timestamp($fichier); |
|
| 60 | 60 | if (!file_exists($fichier)) { |
| 61 | 61 | return false; |
| 62 | 62 | } |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | $image = file_get_contents($fichier); |
| 66 | 66 | } |
| 67 | 67 | else { |
| 68 | - $image = file_get_contents($fichier, false,null,0, $maxlen); |
|
| 68 | + $image = file_get_contents($fichier, false, null, 0, $maxlen); |
|
| 69 | 69 | } |
| 70 | 70 | // est-ce bien une image svg ? |
| 71 | 71 | if (strpos($image, "<svg") !== false) { |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | if (($ps = stripos($debut_fichier, "<svg")) !== false) { |
| 88 | 88 | |
| 89 | 89 | $pe = stripos($debut_fichier, ">", $ps); |
| 90 | - $balise_svg = substr($debut_fichier, $ps, $pe - $ps +1); |
|
| 90 | + $balise_svg = substr($debut_fichier, $ps, $pe - $ps + 1); |
|
| 91 | 91 | |
| 92 | 92 | if (preg_match_all(",([\w:\-]+)=,Uims", $balise_svg, $matches)) { |
| 93 | 93 | if (!function_exists('extraire_attribut')) { |
@@ -127,29 +127,29 @@ discard block |
||
| 127 | 127 | * @return bool|float|int |
| 128 | 128 | */ |
| 129 | 129 | function svg_dimension_to_pixels($dimension, $precision = 2) { |
| 130 | - if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)){ |
|
| 130 | + if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)) { |
|
| 131 | 131 | switch (strtolower($m[2])) { |
| 132 | 132 | case '%': |
| 133 | 133 | // on ne sait pas faire :( |
| 134 | 134 | return false; |
| 135 | 135 | break; |
| 136 | 136 | case 'em': |
| 137 | - return round($m[1]*16, $precision); // 16px font-size par defaut |
|
| 137 | + return round($m[1] * 16, $precision); // 16px font-size par defaut |
|
| 138 | 138 | break; |
| 139 | 139 | case 'ex': |
| 140 | - return round($m[1]*16, $precision); // 16px font-size par defaut |
|
| 140 | + return round($m[1] * 16, $precision); // 16px font-size par defaut |
|
| 141 | 141 | break; |
| 142 | 142 | case 'pc': |
| 143 | - return round($m[1]*16, $precision); // 1/6 inch = 96px/6 in CSS |
|
| 143 | + return round($m[1] * 16, $precision); // 1/6 inch = 96px/6 in CSS |
|
| 144 | 144 | break; |
| 145 | 145 | case 'cm': |
| 146 | - return round($m[1]*96/2.54, $precision); // 96px / 2.54cm; |
|
| 146 | + return round($m[1] * 96 / 2.54, $precision); // 96px / 2.54cm; |
|
| 147 | 147 | break; |
| 148 | 148 | case 'mm': |
| 149 | - return round($m[1]*96/25.4, $precision); // 96px / 25.4mm; |
|
| 149 | + return round($m[1] * 96 / 25.4, $precision); // 96px / 25.4mm; |
|
| 150 | 150 | break; |
| 151 | 151 | case 'in': |
| 152 | - return round($m[1]*96, $precision); // 1 inch = 96px in CSS |
|
| 152 | + return round($m[1] * 96, $precision); // 1 inch = 96px in CSS |
|
| 153 | 153 | break; |
| 154 | 154 | case 'px': |
| 155 | 155 | case 'pt': |
@@ -187,15 +187,15 @@ discard block |
||
| 187 | 187 | * inserer au debut (true) ou a la fin (false) |
| 188 | 188 | * @return string |
| 189 | 189 | */ |
| 190 | -function svg_insert_shapes($svg, $shapes, $start=true) { |
|
| 190 | +function svg_insert_shapes($svg, $shapes, $start = true) { |
|
| 191 | 191 | |
| 192 | 192 | if ($start === false or $start === 'end') { |
| 193 | - $svg = str_replace("</svg>", $shapes . "</svg>", $svg); |
|
| 193 | + $svg = str_replace("</svg>", $shapes."</svg>", $svg); |
|
| 194 | 194 | } |
| 195 | 195 | else { |
| 196 | 196 | $p = stripos($svg, "<svg"); |
| 197 | 197 | $p = strpos($svg, ">", $p); |
| 198 | - $svg = substr_replace($svg, $shapes, $p+1, 0); |
|
| 198 | + $svg = substr_replace($svg, $shapes, $p + 1, 0); |
|
| 199 | 199 | } |
| 200 | 200 | return $svg; |
| 201 | 201 | } |
@@ -211,10 +211,10 @@ discard block |
||
| 211 | 211 | */ |
| 212 | 212 | function svg_clip_in_box($svg, $x, $y, $width, $height) { |
| 213 | 213 | $rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />"; |
| 214 | - $id = 'clip-'.substr(md5($rect . strlen($svg)),0,8); |
|
| 214 | + $id = 'clip-'.substr(md5($rect.strlen($svg)), 0, 8); |
|
| 215 | 215 | $clippath = "<clipPath id=\"$id\">$rect</clipPath>"; |
| 216 | 216 | $g = "<g clip-path=\"url(#$id)\">"; |
| 217 | - $svg = svg_insert_shapes($svg, $clippath . $g); |
|
| 217 | + $svg = svg_insert_shapes($svg, $clippath.$g); |
|
| 218 | 218 | $svg = svg_insert_shapes($svg, "</g>", false); |
| 219 | 219 | return $svg; |
| 220 | 220 | } |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | |
| 233 | 233 | list($balise_svg, $attributs) = $svg_infos; |
| 234 | 234 | if (!isset($attributs['viewBox'])) { |
| 235 | - $attributs['viewBox'] = "0 0 " . $attributs['width'] . " " . $attributs['height']; |
|
| 235 | + $attributs['viewBox'] = "0 0 ".$attributs['width']." ".$attributs['height']; |
|
| 236 | 236 | } |
| 237 | 237 | $attributs['width'] = strval($new_width); |
| 238 | 238 | $attributs['height'] = strval($new_height); |
@@ -250,14 +250,14 @@ discard block |
||
| 250 | 250 | * @return string |
| 251 | 251 | */ |
| 252 | 252 | function svg_couleur_to_hexa($couleur) { |
| 253 | - if (strpos($couleur, "rgb(")===0) { |
|
| 253 | + if (strpos($couleur, "rgb(") === 0) { |
|
| 254 | 254 | $c = explode(',', substr($couleur, 4)); |
| 255 | 255 | $couleur = _couleur_dec_to_hex(intval($c[0]), intval($c[1]), intval($c[2])); |
| 256 | 256 | } |
| 257 | 257 | else { |
| 258 | 258 | $couleur = couleur_html_to_hex($couleur); |
| 259 | 259 | } |
| 260 | - $couleur = '#'.ltrim($couleur,'#'); |
|
| 260 | + $couleur = '#'.ltrim($couleur, '#'); |
|
| 261 | 261 | return $couleur; |
| 262 | 262 | } |
| 263 | 263 | |
@@ -267,9 +267,9 @@ discard block |
||
| 267 | 267 | * @return array |
| 268 | 268 | */ |
| 269 | 269 | function svg_couleur_to_rgb($couleur) { |
| 270 | - if (strpos($couleur, "rgb(")===0) { |
|
| 270 | + if (strpos($couleur, "rgb(") === 0) { |
|
| 271 | 271 | $c = explode(',', substr($couleur, 4)); |
| 272 | - return ['red' => intval($c[0]),'green' => intval($c[1]),'blue' => intval($c[2])]; |
|
| 272 | + return ['red' => intval($c[0]), 'green' => intval($c[1]), 'blue' => intval($c[2])]; |
|
| 273 | 273 | } |
| 274 | 274 | return _couleur_hex_to_dec($couleur); |
| 275 | 275 | } |
@@ -357,7 +357,7 @@ discard block |
||
| 357 | 357 | */ |
| 358 | 358 | function svg_force_viewBox_px($img, $force_width_and_height = false) { |
| 359 | 359 | if ($svg = svg_charger($img) |
| 360 | - and $svg_infos = svg_lire_balise_svg($svg)){ |
|
| 360 | + and $svg_infos = svg_lire_balise_svg($svg)) { |
|
| 361 | 361 | |
| 362 | 362 | list($balise_svg, $attributs) = $svg_infos; |
| 363 | 363 | |
@@ -397,7 +397,7 @@ discard block |
||
| 397 | 397 | * @param $new_height |
| 398 | 398 | * @return bool|string |
| 399 | 399 | */ |
| 400 | -function svg_recadrer($img, $new_width, $new_height, $offset_width, $offset_height, $background_color='') { |
|
| 400 | +function svg_recadrer($img, $new_width, $new_height, $offset_width, $offset_height, $background_color = '') { |
|
| 401 | 401 | if ($svg = svg_force_viewBox_px($img) |
| 402 | 402 | and $svg_infos = svg_lire_balise_svg($svg)) { |
| 403 | 403 | |
@@ -423,7 +423,7 @@ discard block |
||
| 423 | 423 | $viewport_oy = round($viewport_oy * $yscale, 2); |
| 424 | 424 | } |
| 425 | 425 | |
| 426 | - if ($viewport_w>$viewBox[2] or $viewport_h>$viewBox[3]) { |
|
| 426 | + if ($viewport_w > $viewBox[2] or $viewport_h > $viewBox[3]) { |
|
| 427 | 427 | $svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]); |
| 428 | 428 | } |
| 429 | 429 | |
@@ -440,7 +440,7 @@ discard block |
||
| 440 | 440 | $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
| 441 | 441 | |
| 442 | 442 | // ajouter un background |
| 443 | - if ($background_color and $background_color!=='transparent') { |
|
| 443 | + if ($background_color and $background_color !== 'transparent') { |
|
| 444 | 444 | $svg = svg_ajouter_background($svg, $background_color); |
| 445 | 445 | } |
| 446 | 446 | |
@@ -458,9 +458,9 @@ discard block |
||
| 458 | 458 | */ |
| 459 | 459 | function svg_ajouter_background($img, $background_color) { |
| 460 | 460 | if ($svg = svg_charger($img) |
| 461 | - and $svg_infos = svg_lire_balise_svg($svg)){ |
|
| 461 | + and $svg_infos = svg_lire_balise_svg($svg)) { |
|
| 462 | 462 | |
| 463 | - if ($background_color and $background_color!=='transparent') { |
|
| 463 | + if ($background_color and $background_color !== 'transparent') { |
|
| 464 | 464 | list($balise_svg, $attributs) = $svg_infos; |
| 465 | 465 | |
| 466 | 466 | $background_color = svg_couleur_to_hexa($background_color); |
@@ -487,9 +487,9 @@ discard block |
||
| 487 | 487 | */ |
| 488 | 488 | function svg_ajouter_voile($img, $background_color, $opacity) { |
| 489 | 489 | if ($svg = svg_charger($img) |
| 490 | - and $svg_infos = svg_lire_balise_svg($svg)){ |
|
| 490 | + and $svg_infos = svg_lire_balise_svg($svg)) { |
|
| 491 | 491 | |
| 492 | - if ($background_color and $background_color!=='transparent') { |
|
| 492 | + if ($background_color and $background_color !== 'transparent') { |
|
| 493 | 493 | list($balise_svg, $attributs) = $svg_infos; |
| 494 | 494 | |
| 495 | 495 | $background_color = svg_couleur_to_hexa($background_color); |
@@ -516,10 +516,10 @@ discard block |
||
| 516 | 516 | */ |
| 517 | 517 | function svg_transformer($img, $attributs) { |
| 518 | 518 | if ($svg = svg_charger($img) |
| 519 | - and $svg_infos = svg_lire_balise_svg($svg)){ |
|
| 519 | + and $svg_infos = svg_lire_balise_svg($svg)) { |
|
| 520 | 520 | |
| 521 | 521 | if ($attributs) { |
| 522 | - list($balise_svg, ) = $svg_infos; |
|
| 522 | + list($balise_svg,) = $svg_infos; |
|
| 523 | 523 | $g = "<g"; |
| 524 | 524 | foreach ($attributs as $k=>$v) { |
| 525 | 525 | if (strlen($v)) { |
@@ -546,14 +546,14 @@ discard block |
||
| 546 | 546 | */ |
| 547 | 547 | function svg_apply_filter($img, $filter_def) { |
| 548 | 548 | if ($svg = svg_charger($img) |
| 549 | - and $svg_infos = svg_lire_balise_svg($svg)){ |
|
| 549 | + and $svg_infos = svg_lire_balise_svg($svg)) { |
|
| 550 | 550 | |
| 551 | 551 | if ($filter_def) { |
| 552 | - list($balise_svg, ) = $svg_infos; |
|
| 553 | - $filter_id = "filter-". substr(md5($filter_def . strlen($svg)), 0, 8); |
|
| 552 | + list($balise_svg,) = $svg_infos; |
|
| 553 | + $filter_id = "filter-".substr(md5($filter_def.strlen($svg)), 0, 8); |
|
| 554 | 554 | $filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>"; |
| 555 | 555 | $g = "<g filter=\"url(#$filter_id)\">"; |
| 556 | - $svg = svg_insert_shapes($svg, $filter . $g); |
|
| 556 | + $svg = svg_insert_shapes($svg, $filter.$g); |
|
| 557 | 557 | $svg = svg_insert_shapes($svg, "</g>", false); |
| 558 | 558 | } |
| 559 | 559 | return $svg; |
@@ -604,7 +604,7 @@ discard block |
||
| 604 | 604 | */ |
| 605 | 605 | function svg_flip($img, $HorV) { |
| 606 | 606 | if ($svg = svg_force_viewBox_px($img) |
| 607 | - and $svg_infos = svg_lire_balise_svg($svg)){ |
|
| 607 | + and $svg_infos = svg_lire_balise_svg($svg)) { |
|
| 608 | 608 | |
| 609 | 609 | list($balise_svg, $atts) = $svg_infos; |
| 610 | 610 | $viewBox = explode(' ', $atts['viewBox']); |
@@ -612,14 +612,14 @@ discard block |
||
| 612 | 612 | if (!in_array($HorV, ['h', 'H'])) { |
| 613 | 613 | $transform = "scale(-1,1)"; |
| 614 | 614 | |
| 615 | - $x = intval($viewBox[0]) + intval($viewBox[2]/2); |
|
| 615 | + $x = intval($viewBox[0]) + intval($viewBox[2] / 2); |
|
| 616 | 616 | $mx = -$x; |
| 617 | 617 | $transform = "translate($x, 0) $transform translate($mx, 0)"; |
| 618 | 618 | } |
| 619 | 619 | else { |
| 620 | 620 | $transform = "scale(1,-1)"; |
| 621 | 621 | |
| 622 | - $y = intval($viewBox[1]) + intval($viewBox[3]/2); |
|
| 622 | + $y = intval($viewBox[1]) + intval($viewBox[3] / 2); |
|
| 623 | 623 | $my = -$y; |
| 624 | 624 | $transform = "translate(0, $y) $transform translate(0, $my)"; |
| 625 | 625 | } |
@@ -641,7 +641,7 @@ discard block |
||
| 641 | 641 | */ |
| 642 | 642 | function svg_rotate($img, $angle, $center_x, $center_y) { |
| 643 | 643 | if ($svg = svg_force_viewBox_px($img) |
| 644 | - and $svg_infos = svg_lire_balise_svg($svg)){ |
|
| 644 | + and $svg_infos = svg_lire_balise_svg($svg)) { |
|
| 645 | 645 | |
| 646 | 646 | list($balise_svg, $atts) = $svg_infos; |
| 647 | 647 | $viewBox = explode(' ', $atts['viewBox']); |