48836a977839675b309a3181b439536a012fc1d1
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2014 *
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 \***************************************************************************/
13 if (!defined("_ECRIRE_INC_VERSION")) return;
18 * http://code.spip.net/@action_tourner_dist
20 * lorsque les arguments sont passes dans arg en GET :
23 * @param int $id_document
25 * angle de rotation en degre>0
28 function action_tourner_dist($id_document=null, $angle=null) {
29 if (is_null($id_document) OR is_null($angle)){
30 $securiser_action = charger_fonction('securiser_action', 'inc');
31 $arg = $securiser_action();
33 if (!preg_match(",^\W*(\d+)\W?(-?\d+)$,", $arg, $r)) {
34 spip_log("action_tourner_dist $arg pas compris");
38 list($id_document,$angle) = $r;
42 if ($id_document AND autoriser('modifier','document',$id_document))
43 action_tourner_post($id_document,$angle);
49 * http://code.spip.net/@action_tourner_post
51 * @param int $id_document
53 * angle de rotation en degre>0
56 function action_tourner_post($id_document,$angle)
58 $row = sql_fetsel("fichier,extension", "spip_documents", "id_document=".intval($id_document));
62 include_spip('inc/charsets'); # pour le nom de fichier
63 include_spip('inc/documents');
64 // Fichier destination : on essaie toujours de repartir de l'original
67 include_spip('inc/distant'); # pour copie_locale
68 $src = _DIR_RACINE
. copie_locale(get_spip_doc($row['fichier']));
69 if (preg_match(',^(.*)-r(90|180|270)\.([^.]+)$,', $src, $match)) {
71 $src = $match[1].'.'.$match[3];
72 $var_rot +
= intval($match[2]);
74 $var_rot = ((360 +
$var_rot) %
360); // 0, 90, 180 ou 270
77 $dest = preg_replace(',\.[^.]+$,', '-r'.$var_rot.'$0', $src);
78 spip_log("rotation $var_rot $src : $dest");
80 include_spip('inc/filtres');
81 include_spip('public/parametrer'); // charger les fichiers fonctions #bugfix spip 2.1.0
82 $res = filtrer('image_rotation',$src,$var_rot);
83 $res = filtrer('image_format',$res,$row['extension']);
85 list($hauteur,$largeur) = taille_image($res);
86 $res = extraire_attribut($res,'src');
88 include_spip('inc/getdocument');
89 deplacer_fichier_upload($res,$dest);
93 $size_image = @getimagesize
($dest);
94 $largeur = $size_image[0];
95 $hauteur = $size_image[1];
99 if ($largeur>0 AND $hauteur>0) {
101 'fichier' => set_spip_doc($dest),
102 'largeur'=>$largeur, 'hauteur'=>$hauteur,
103 'distant'=>'non' // le document n'est plus distant apres une transformation
105 if ($taille = @filesize
($dest))
106 $set['taille'] = $taille;
107 sql_updateq('spip_documents', $set, "id_document=".intval($id_document));
109 spip_log("rotation : j'efface $effacer");
110 spip_unlink($effacer);
112 // pipeline pour les plugins
113 pipeline('post_edition',
116 'table' => 'spip_documents',
117 'table_objet' => 'documents',
118 'spip_table_objet' => 'spip_documents',
120 'id_objet' => $id_document,
121 'champs' => array('rotation'=>$angle,'orientation'=>$var_rot,'fichier'=>$row['fichier']),
122 'serveur' => $serveur,
132 // Appliquer l'EXIF orientation
133 // cf. http://trac.rezo.net/trac/spip/ticket/1494
134 // http://code.spip.net/@tourner_selon_exif_orientation
135 function tourner_selon_exif_orientation($id_document, $fichier) {
137 if (function_exists('exif_read_data')
138 AND $exif = exif_read_data($fichier)
140 $ort = $exif['IFD0']['Orientation']
141 OR $ort = $exif['Orientation'])
143 spip_log("rotation: $ort");
154 action_tourner_post(array(null,$id_document, $rot));