1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
| <?php
// Afficher les erreurs à l'écran
ini_set('display_errors', 1);
// Enregistrer les erreurs dans un fichier de log
ini_set('log_errors', 1);
// Nom du fichier qui enregistre les logs (attention aux droits à l'écriture)
ini_set('error_log', dirname(__file__) . '/log_error_php.txt');
// Afficher les erreurs et les avertissements
error_reporting(e_all);
header("Content-type: image/png");
//Script de prévision "Météo de Quetigny" version 1.0
//du 14/10/14
//par T.RENAULT
//--------------------------------------------------------
// Fonction de lecture du fichier XML
//function lit_xml($chaine,$isFile,$item,$champs) {
// on lit le fichier ou la chaîne
// if($isFile){
//$chaine = @file_get_contents($chaine);
//}
//if($chaine) {
// on explode sur <item>
//$tmp = preg_split("/<\/?".$item.">/",$chaine);
// pour chaque <item>
//for($i=1;$i<sizeof($tmp);$i++)
// on lit les champs demandés <champ>
// foreach($champs as $champ) {
// $tmp2 = preg_split("/<\/?".$champ.">/",$tmp[$i]);
// on ajoute au tableau
//$tmp3[$champ][] = trim(@$tmp2[1]);
//}
// et on retourne le tableau
//return @$tmp3;
//}
// else
//return null;
//}
//Chargement de l'API WU !
//$url = "http://api.wunderground.com/api/2dcd87d89fe4ac00/forecast/lang:FR/q/France/Quetigny.xml";
////$url = "http://api.wunderground.com/api/2dcd87d89fe4ac00/forecast/lang:FR/q/France/Quetigny.xml";
////$url = "http://thierry-renault.fr/meteo.quetigny/previsionmt.xml";
//Lecture de l'API WU !
//$xmlprev1 = lit_xml($url,true,"forecastday",array("title","fcttext_metric","icon"));
//$xmlprev2 = lit_xml($url,true,"forecastday",array("icon"));
//Heure de la prévision
//$heureprev = $xmlprev0["date"][0];
//Generation de prévision + jour de la prévision
//$xmlprev1["fcttext_metric"] = str_replace('<![CDATA[' ,'',$xmlprev1["fcttext_metric"]);
//$xmlprev1["fcttext_metric"] = str_replace(']]>' ,'',$xmlprev1["fcttext_metric"]);
//Generation des icones
//$icon0 = $xmlprev1["icon"][0];
//$icon1 = $xmlprev1["icon"][2];
//$icon2 = $xmlprev1["icon"][4];
//$icon3 = $xmlprev1["icon"][6];
//$icon4 = $xmlprev1["icon"][8];
//$icon5 = $xmlprev1["icon"][10];
//$icon6 = $xmlprev1["icon"][12];
//$icon7 = $xmlprev1["icon"][14];
//-------------------------
//$icomt = imagecreatefrompng("/forecast/images/$icon0.gif"); // Le logo est la source
// on se connecte à MySQLi
$db = mysqli_connect('dbxxx', 'dboxxx', 'xxxx','dbxxxx');
// on selectionne la base
mysqli_select_db('dbxxxxxx',$db);
// on cree la requête SQLi
$sql = "select time as datetime, temp,datjour,baro,dailyrain,rainrate,monthrain,humidite,windspeed,rafale,rose from meteo1 WHERE curdate() = date";
$result = mysqli_query($db,$sql);
$data = array();
while ($row = mysqli_fetch_array($result)) {
extract($row);
}
mysqli_close($db,$sql);
$today = date("d/m/y"); //jour mois année
$heure = date('G'); //heure
$minute = date('i'); //minute
//TEST
//$baro = 1011;
//$heure = "18";
//prevision manuelle
if ($rainrate > 1):
if ($temp < 2):
if ($temp < 0) :
$icon0 = "chancesnow";
else:
$icon0 = "chancesleet";
endif;
else:
$icon0 = "chancerain";
endif;
else:
if ($baro >= 1025) :
//1025 soleil
if($heure <= "6" or $heure >= "21") :
$icon0 = "nt_clear";
else:
$icon0 = "clear";
endif;
else:
if ($baro >= 1020) :
//1020 peu gris soleil
if($heure <= "6" or $heure >= "21") :
$icon0 = "nt_partlycloudy";
else:
$icon0 = "partlycloudy";
endif;
else:
if ($baro >= 1015) :
//1015 gris et soleil
if($heure <= "6" or $heure >= "21") :
$icon0 = "nt_cloudy";
else:
$icon0 = "cloudy";
endif;
else:
if ($baro <= 1010) :
//1010 gris
$icon0 = "mostlycloudy";
else:
if($heure <= "6" or $heure >= "21") :
$icon0 = "nt_cloudy";
else:
$icon0 = "cloudy";
endif;
endif;
endif;
endif;
endif;
endif;
//----
//Brouillard
if ($humidite >= 98):
$icon0 = "fog";
else:
endif;
//----
$urlico = "http://meteo-quetigny.thierry-renault.fr/forecast/images/" . $icon0 . ".gif";
$source = imagecreatefrompng($urlico);
//temp
$x = 320;
$y = 208;
//date
$x0 = 20;
$y0 = 30 +5;
//baro
$x1 = 20;
$y1 = 50 +10;
//hygro
$x2 = 20;
$y2 = 65 +10;
//rose
$x3 = 20;
$y3 = 80 +10;
//vent
$x6 = 20;
$y6 = 95 +15;
//rafale vent
$x6b = 20;
$y6b = 110 +15;
//pluie1h
$x7 = 20;
$y7 = 125 +20;
//pluiejour
$x8 = 20;
$y8 = 140 +20;
//pluiemois
$x9 = 20;
$y9 = 155 +20;
$im = imagecreatefrompng('http://meteo-quetigny.thierry-renault.fr/imagejourvide.png');
include('GDMagic.php');
$noir = imagecolorallocate($im, 56, 53, 54);
//ajout temperature
// 1 image, 2 taille police, 3 valeur x ecriture, 4 valeur y ecriture, 5 couleur
$font = './verdana.ttf';
$fontb = './verdanab.ttf';
//imagestring($im, 4, $x, $y, "$temp °C", $noir);
imagettftext($im, 22, 0, $x, $y, $noir, $font, "$temp °C");
imagettftext($im, 10, 0, $x0, $y0, $noir, $fontb, "Données du $today" . " à $heure" . "h" ."$minute :");
imagettftext($im, 8, 0, $x1, $y1, $noir, $font, "- Pression relative : $baro hPa");
imagettftext($im, 8, 0, $x2, $y2, $noir, $font, "- Hygrométrie relative : $humidite %");
imagettftext($im, 8, 0, $x3, $y3, $noir, $font, "- Point de rosée : $rose °C");
imagettftext($im, 8, 0, $x6, $y6, $noir, $font, "- Vitesse du vent : $windspeed km/h");
imagettftext($im, 8, 0, $x6b, $y6b, $noir, $font, "- Rafale du vent : $rafale km/h");
imagettftext($im, 8, 0, $x7, $y7, $noir, $font, "- Pluie année : $rainrate mm");
imagettftext($im, 8, 0, $x8, $y8, $noir, $font, "- Pluie 1 heure : $dailyrain mm");
imagettftext($im, 8, 0, $x9, $y9, $noir, $font, "- Pluie du mois : $monthrain mm");
//icone meteo
imagealphablending($source,true);
//imagecopy($dest, $src, 0, 0, 20, 13, 80, 40);
imagecopy($im, $source, 292, 25, 0, 0, 128, 128);
imagepng($im, "imagejour.png");
imagepng($im);
imagedestroy($im);
?> |
Partager