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
|
<?php
// {inclusion de la classe sql etc..}
$map = "./img/france_empty.png";
$output = "carte.png";
$num_dept = "./img/carte_dept.png";
list($width, $height, $type, $attr) = getimagesize($map);
$img = imagecreatefrompng($map);
$img2 = imagecreatefrompng($num_dept);
// LES COULEURS
$border = ImageColorAt ($img, 100, 100); // Pour les couleurs du bord... choisir blanc avec imagecolorallocate ne marche pas T_T
//$border = imagecolorallocate($img, 255, 255, 255);
$black = imagecolorallocate($img, 0, 0, 0); // pour le texte
$ciel = imagecolorallocate($img,200,200,255); // 1 ou 2
$green = imagecolorallocate($img, 0, 255, 0); // 3 à 5
$jaune = imagecolorallocate($img,220,232,0); // 5 à 10
$orange = imagecolorallocate($img,250,157,0); // 11 à 25
$red = imagecolorallocate($img, 255, 0, 0); // + de 25
$query = $mysql->query_mysql("SELECT count(departement) AS nbmembres, nom_dept, departement, X, Y FROM `geo_dept`, `membres`, `departements` WHERE pays='FR' AND departement=id_dept AND id_dept=code GROUP BY departement");
// REMPLISSAGE DES DEPARTEMENTS
// imagefilltoborder ( resource $image, int $x, int $y, int $border, int $color )
while ($row = mysql_fetch_assoc($query)) {
$nbmembres = $row['nbmembres'];
if($nbmembres < 3) {
$color = $ciel;
} elseif($nbmembres > 2 && $nbmembres < 6) {
$color = $green;
} elseif($nbmembres > 5 && $nbmembres < 11) {
$color = $jaune;
} elseif($nbmembres > 10 && $nbmembres < 26) {
$color = $orange;
} else {
$color = $red;
}
imagefilltoborder($img, $row['X'], $row['Y'], $border, $color);
}
mysql_free_result($query);
// INSCRUSTATION DES NUMEROS DE DEPARTEMENTS ET DE LA LEGENDE
// imagecopymerge ( resource $dst_im, resource $src_im, int $dst_x, int $dst_y, int $src_x, int $src_y, int $src_w, int $src_h, int $pct )
imagecopymerge($img, $img2, 0, 0, $width, $height, 0, 0, $width, $height, 0);
imagepng($img,$output);
imagedestroy($img);
imagedestroy($img2); |
Partager