1 | <?php |
---|
2 | |
---|
3 | /***************************************************************************\ |
---|
4 | * SPIP, Systeme de publication pour l'internet * |
---|
5 | * * |
---|
6 | * Copyright (c) 2001-2009 * |
---|
7 | * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James * |
---|
8 | * * |
---|
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 | \***************************************************************************/ |
---|
12 | |
---|
13 | if (!defined("_ECRIRE_INC_VERSION")) return; |
---|
14 | |
---|
15 | // http://doc.spip.org/@action_tourner_dist |
---|
16 | function action_tourner_dist($arg=null) { |
---|
17 | if(is_null($arg)){ |
---|
18 | $securiser_action = charger_fonction('securiser_action', 'inc'); |
---|
19 | $arg = $securiser_action(); |
---|
20 | } |
---|
21 | |
---|
22 | if (!preg_match(",^\W*(\d+)\W?(-?\d+)$,", $arg, $r)) { |
---|
23 | spip_log("action_tourner_dist $arg pas compris"); |
---|
24 | } else action_tourner_post($r[1],$r[2]); |
---|
25 | } |
---|
26 | |
---|
27 | // http://doc.spip.org/@action_tourner_post |
---|
28 | function action_tourner_post($id_document,$angle) |
---|
29 | { |
---|
30 | $row = sql_fetsel("fichier,extension", "spip_documents", "id_document=".intval($id_document)); |
---|
31 | |
---|
32 | if (!$row) return; |
---|
33 | |
---|
34 | include_spip('inc/charsets'); # pour le nom de fichier |
---|
35 | include_spip('inc/documents'); |
---|
36 | // Fichier destination : on essaie toujours de repartir de l'original |
---|
37 | $var_rot = $angle; |
---|
38 | |
---|
39 | include_spip('inc/distant'); # pour copie_locale |
---|
40 | $src = _DIR_RACINE . copie_locale(get_spip_doc($row['fichier'])); |
---|
41 | if (preg_match(',^(.*)-r(90|180|270)\.([^.]+)$,', $src, $match)) { |
---|
42 | $effacer = $src; |
---|
43 | $src = $match[1].'.'.$match[3]; |
---|
44 | $var_rot += intval($match[2]); |
---|
45 | } |
---|
46 | $var_rot = ((360 + $var_rot) % 360); // 0, 90, 180 ou 270 |
---|
47 | |
---|
48 | if ($var_rot > 0) { |
---|
49 | $dest = preg_replace(',\.[^.]+$,', '-r'.$var_rot.'$0', $src); |
---|
50 | spip_log("rotation $var_rot $src : $dest"); |
---|
51 | |
---|
52 | include_spip('inc/filtres'); |
---|
53 | include_spip('public/parametrer'); // charger les fichiers fonctions #bugfix spip 2.1.0 |
---|
54 | $res = filtrer('image_rotation',$src,$var_rot); |
---|
55 | $res = filtrer('image_format',$res,$row['extension']); |
---|
56 | |
---|
57 | list($hauteur,$largeur) = taille_image($res); |
---|
58 | $res = extraire_attribut($res,'src'); |
---|
59 | |
---|
60 | include_spip('inc/getdocument'); |
---|
61 | deplacer_fichier_upload($res,$dest); |
---|
62 | } |
---|
63 | else { |
---|
64 | $dest = $src; |
---|
65 | $size_image = @getimagesize($dest); |
---|
66 | $largeur = $size_image[0]; |
---|
67 | $hauteur = $size_image[1]; |
---|
68 | } |
---|
69 | |
---|
70 | // succes ! |
---|
71 | if ($largeur>0 AND $hauteur>0) { |
---|
72 | $set = array( |
---|
73 | 'fichier' => set_spip_doc($dest), |
---|
74 | 'largeur'=>$largeur, 'hauteur'=>$hauteur, |
---|
75 | 'distant'=>'non' // le document n'est plus distant apres une transformation |
---|
76 | ); |
---|
77 | if ($taille = @filesize($dest)) |
---|
78 | $set['taille'] = $taille; |
---|
79 | sql_updateq('spip_documents', $set, "id_document=".intval($id_document)); |
---|
80 | if ($effacer) { |
---|
81 | spip_log("rotation : j'efface $effacer"); |
---|
82 | spip_unlink($effacer); |
---|
83 | } |
---|
84 | // pipeline pour les plugins |
---|
85 | pipeline('post_edition', |
---|
86 | array( |
---|
87 | 'args' => array( |
---|
88 | 'table' => 'spip_documents', |
---|
89 | 'table_objet' => 'documents', |
---|
90 | 'spip_table_objet' => 'spip_documents', |
---|
91 | 'type' =>'document', |
---|
92 | 'id_objet' => $id_document, |
---|
93 | 'champs' => array('rotation'=>$angle,'orientation'=>$var_rot,'fichier'=>$row['fichier']), |
---|
94 | 'serveur' => $serveur, |
---|
95 | 'action'=>'tourner', |
---|
96 | ), |
---|
97 | 'data' => $set |
---|
98 | ) |
---|
99 | ); |
---|
100 | } |
---|
101 | |
---|
102 | } |
---|
103 | |
---|
104 | // Appliquer l'EXIF orientation |
---|
105 | // cf. http://trac.rezo.net/trac/spip/ticket/1494 |
---|
106 | // http://doc.spip.org/@tourner_selon_exif_orientation |
---|
107 | function tourner_selon_exif_orientation($id_document, $fichier) { |
---|
108 | |
---|
109 | if (function_exists('exif_read_data') |
---|
110 | AND $exif = exif_read_data($fichier) |
---|
111 | AND ( |
---|
112 | $ort = $exif['IFD0']['Orientation'] |
---|
113 | OR $ort = $exif['Orientation']) |
---|
114 | ) { |
---|
115 | spip_log("rotation: $ort"); |
---|
116 | $rot = null; |
---|
117 | switch ($ort) { |
---|
118 | case 3: |
---|
119 | $rot = 180; |
---|
120 | case 6: |
---|
121 | $rot = 90; |
---|
122 | case 8: |
---|
123 | $rot = -90; |
---|
124 | } |
---|
125 | if ($rot) |
---|
126 | action_tourner_post(array(null,$id_document, $rot)); |
---|
127 | } |
---|
128 | } |
---|
129 | |
---|
130 | ?> |
---|