3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2019 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
14 * Informations meta d'un SVG
16 * @package SPIP\Medias\Metadata
19 if (!defined('_ECRIRE_INC_VERSION')) {
22 include_spip('inc/autoriser');
25 * Déterminer les dimensions d'un svg, et enlever ses scripts si nécessaire
27 * On utilise safehtml qui n'est pas apropriée pour ça en attendant mieux
28 * cf http://www.slideshare.net/x00mario/the-image-that-called-me
29 * http://heideri.ch/svgpurifier/SVGPurifier/index.php
32 * @return array Tableau (largeur, hauteur)
34 function metadata_svg_dist($file) {
37 $texte = spip_file_get_contents($file);
39 // Securite si pas autorise : virer les scripts et les references externes
40 // sauf si on est en mode javascript 'ok' (1), cf. inc_version
41 if ($GLOBALS['filtrer_javascript'] < 1
42 and !autoriser('televerser', 'script')
44 include_spip('inc/texte');
45 $new = trim(safehtml($texte));
47 if (substr($new, 0, 2) == ']>') {
48 $new = ltrim(substr($new, 2));
51 ecrire_fichier($file, $texte = $new);
55 $width = $height = 150;
56 if (preg_match(',<svg[^>]+>,', $texte, $s)) {
58 if (preg_match(',\WviewBox\s*=\s*.\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+),i', $s, $r)) {
62 // si la taille est en centimetre, estimer le pixel a 1/64 de cm
63 if (preg_match(',\Wwidth\s*=\s*.(\d+)([^"\']*),i', $s, $r)) {
71 if (preg_match(',\Wheight\s*=\s*.(\d+)([^"\']*),i', $s, $r)) {
81 $meta['largeur'] = $width;
82 $meta['hauteur'] = $height;