IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Image graphique calculée


Sujet :

Langage PHP

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    11
    Détails du profil
    Informations personnelles :
    Âge : 67
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Avril 2008
    Messages : 11
    Points : 4
    Points
    4
    Par défaut Image graphique calculée
    Dans une application de calcul d'enceintes et haut-parleur, je souhaite afficher le graphe de la courbe de réponse.
    Calculs et graphe sont réalisés en php

    Il y a deux programmes :
    Le premier calcule la courbe de réponse, avec un couple de valeur, Frequence sur X, $dbabr sur Y.
    Le deuxième calcule l'image pour l'afficher dans le premier programme.Je tiens particulièrement à l'affichage dans le premier programme.

    Le problème se trouve dans le passage des paramètres entre les programmes.
    Le GET utilisé fonctionne, mais je suis limité dans le nombre de valeurs qui peuvent être passées.

    Premier programme :
    Les fonctions sont à l'adresse http://www.petoindominique.fr/ à la place de ../
    Le pas de calcul est le 1/12e d'octave, $f = $f*pow(2,1/12) ; à cause de la limitation du nombre de valeurs qui passent

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    <?php
    include("../mysql_s/fonction_br.php");
    include("../mysql_s/fonction_room_gain.php");
     
    //Valeurs par défaut
    $fs = 25;
    $fb = 30;
    $fb_aff = number_format($fb, 1, '.', '') ;
    $vas = 65;
    $volbr = 50;
    $volbr_aff = number_format($volbr, 1, '.', '') ;
    $qb = 6.7;
    $qts = 0.31;
    $froomgain = 50;
    $proomgain = 0;
    $sens_aff = 92.2;
     
    // boucle de calcul
    $f = 10;
    $tension = sqrt(8) ;
    $i = 0;
    $dbabr=array();
    while ($f <= 320)
    {
    $dbabr[$i][1] = reponse($f, $fs, $fb, $vas, $volbr, $qb, $qts, $froomgain, $proomgain) ;
    $dbabr[$i][0] = $f;
    $f = $f*pow(2,1/12) ;
    $i++;
    }
    ?>
     
    <p align="center"><font face="Arial" size="2"><b>Courbe de réponse du
    <?php echo "$marque"; ?> <?php echo "$reference"; ?>, VB = <?php echo "$volbr_aff"; ?> L, FB = <?php echo "$fb_aff"; ?> Hz, le 0 dB correspond à <?php echo "$sens_aff"; ?> dB/2.83V/m.</b></font></p>
    <p align="center">
    <img src="../mysql_s/graph_test.php?dbabr=<?php echo serialize($dbabr); ?> alt="courbe de réponse bass-reflex"></p>
    <p align="center"><font face="Arial" size="2">Tracé en 1/12<sup>e</sup> d'octave.</font></p>
    Calcul de l'image : graph_test.php
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    <?php
     
    $dbabr = unserialize($_GET['dbabr']);
     
    $limsupy = 10;
    $liminfy = -15;
    $pasy = $limsupy-$liminfy;
     
    $largeur = 800;
    $hauteur = 400;
    $originex = $largeur/20;
    $originey = $hauteur/20;
    $largeurx = $largeur-$originex;
    $hauteury = $hauteur-$originey;
     
    $image = imagecreate($largeur, $hauteur);
    $fond = imagecolorallocate($image, 220, 220, 220);
    $trait = imagecolorallocate($image, 32, 32, 32);
    $rouge = imagecolorallocate($image, 255, 0, 0);
    $vert = imagecolorallocate($image, 0, 255, 0);
    $bleu = imagecolorallocate($image, 0, 0, 255);
    $gris = imagecolorallocate($image, 160, 160, 160);
    $noir = imagecolorallocate($image, 0, 0, 0);
     
    //Echelle
    $octavex = log10(320/10)/log10(2);
    $echellex = ($largeurx-$originex)/$octavex;
    $zeroy = ($hauteury-$originey)/$pasy*$limsupy+$originey;
    $echelley = ($hauteury-$originey)/$pasy;
     
    //Traits verticaux normalisés
    $p1xaff = log10(10/10)/log10(2)*$echellex+$originex;
    imageline( $image, $p1xaff, $originey, $p1xaff, $hauteury, $noir);
    imagestring( $image, 3, $p1xaff, 8, "10", $noir);
    $p1xaff = log10(15/10)/log10(2)*$echellex+$originex;
    imageline( $image, $p1xaff, $originey, $p1xaff, $hauteury, $gris);
    $p1xaff = log10(20/10)/log10(2)*$echellex+$originex;
    imageline( $image, $p1xaff, $originey, $p1xaff, $hauteury, $noir);
    imagestring( $image, 3, $p1xaff, 8, "20", $noir);
    imagestring( $image, 3, $p1xaff, 3+$hauteury, "20", $noir);
    $p1xaff = log10(30/10)/log10(2)*$echellex+$originex;
    imageline( $image, $p1xaff, $originey, $p1xaff, $hauteury, $gris);
    $p1xaff = log10(40/10)/log10(2)*$echellex+$originex;
    imageline( $image, $p1xaff, $originey, $p1xaff, $hauteury, $gris);
    $p1xaff = log10(50/10)/log10(2)*$echellex+$originex;
    imageline( $image, $p1xaff, $originey, $p1xaff, $hauteury, $noir);
    imagestring( $image, 3, $p1xaff, 8, "50", $noir);
    imagestring( $image, 3, $p1xaff, 3+$hauteury, "50", $noir);
    $p1xaff = log10(60/10)/log10(2)*$echellex+$originex;
    imageline( $image, $p1xaff, $originey, $p1xaff, $hauteury, $gris);
    $p1xaff = log10(70/10)/log10(2)*$echellex+$originex;
    imageline( $image, $p1xaff, $originey, $p1xaff, $hauteury, $gris);
    $p1xaff = log10(80/10)/log10(2)*$echellex+$originex;
    imageline( $image, $p1xaff, $originey, $p1xaff, $hauteury, $gris);
    $p1xaff = log10(90/10)/log10(2)*$echellex+$originex;
    imageline( $image, $p1xaff, $originey, $p1xaff, $hauteury, $gris);
    $p1xaff = log10(100/10)/log10(2)*$echellex+$originex;
    imageline( $image, $p1xaff, $originey, $p1xaff, $hauteury, $noir);
    imagestring( $image, 3, $p1xaff, 8, "100", $noir);
    imagestring( $image, 3, $p1xaff, 3+$hauteury, "100", $noir);
    $p1xaff = log10(150/10)/log10(2)*$echellex+$originex;
    imageline( $image, $p1xaff, $originey, $p1xaff, $hauteury, $gris);
    $p1xaff = log10(200/10)/log10(2)*$echellex+$originex;
    imageline( $image, $p1xaff, $originey, $p1xaff, $hauteury, $noir);
    imagestring( $image, 3, $p1xaff, 8, "200", $noir);
    imagestring( $image, 3, $p1xaff, 3+$hauteury, "200", $noir);
    $p1xaff = log10(300/10)/log10(2)*$echellex+$originex;
    imageline( $image, $p1xaff, $originey, $p1xaff, $hauteury, $gris);
    imagestring( $image, 3, $p1xaff, 8, "Hz", $noir);
    imagestring( $image, 3, $p1xaff, 3+$hauteury, "Hz", $noir);
     
    //traits horizontaux
    $dbdebut = $limsupy;
    $pash = ($originey-$hauteury)/$pasy;
    $i = 0;
    $db = $dbdebut;
    while ($i <= $pasy)
    {
    if ($db == 10 or $db == 5 or $db == 0 or $db == -5 or $db == -10 or $db == -15)
    {
      imageline( $image, $originex, $originey-$i*$pash, $largeurx, $originey-$i*$pash, $noir);
      if ($db <> 0)
      {
      imagestring( $image, 3, $originex-22, $originey-$i*$pash-5, $db, $noir);
      }
      else
      {
      imagestring( $image, 3, $originex-33, $originey-$i*$pash-5, "0 dB", $noir);
      imagestring( $image, 3, $largeurx+5, $originey-$i*$pash-5, "0 dB", $noir);
      }
    }
    else
    {
      imageline( $image, $originex, $originey-$i*$pash, $largeurx, $originey-$i*$pash, $gris);	
    }
    $i++;
    $db = $db-1;
    }
     
    //Courbe de réponse
    $i = 0;
    while($i<59)
    {
    	$p1x = $dbabr[$i][0];
    	$p1y = $dbabr[$i][1];
    	$room1 = $dbabr[$i][2];
    	$champs1 = $room1+$p1y;
    	$p2x = $dbabr[$i+1][0];
    	$p2y = $dbabr[$i+1][1];
    	$room2 = $dbabr[$i+1][2];
    	$champs2 = $room2+$p2y;
    	$p1xaff = log10($p1x/10)/log10(2)*$echellex+$originex;
    	$p2xaff = log10($p2x/10)/log10(2)*$echellex+$originex;
    	$room1aff = log10($room1/10)/log10(2)*$echellex+$originex;
    	$room2aff = log10($room2/10)/log10(2)*$echellex+$originex;
    	$champs1aff = log10($champs1/10)/log10(2)*$echellex+$originex;
    	$champs2aff = log10($champs2/10)/log10(2)*$echellex+$originex;
    	$p1yaff = $zeroy-$p1y*$echelley;
    	$p2yaff = $zeroy-$p2y*$echelley;
    	imageline( $image, $p1xaff, $p1yaff, $p2xaff, $p2yaff, $rouge);
    //	imageline( $image, $room1aff, $p1yaff, $room2aff, $p2yaff, $vert);
    //	imageline( $image, $champs1aff, $p1yaff, $champs2aff, $p2yaff, $bleu);
    	$i++;
    }
     
     
     
    header("content-type: image/png");
    imagepng($image);
    imagedestroy($image);
    ?>
    Merci a ceux qui pourront m'aider.

    dp

  2. #2
    Membre régulier Avatar de TiEuAM
    Profil pro
    Inscrit en
    Septembre 2008
    Messages
    75
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2008
    Messages : 75
    Points : 101
    Points
    101
    Par défaut
    Salut
    Je peu te proposer de mettre tes valeurs dans une session plutot que passées via GET.

  3. #3
    Membre expert
    Avatar de s.n.a.f.u
    Homme Profil pro
    Développeur Web
    Inscrit en
    Août 2006
    Messages
    2 760
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Août 2006
    Messages : 2 760
    Points : 3 545
    Points
    3 545
    Par défaut
    Ou de passer un tableau sérialisé
    • Avant de poser une question, n'hésitez pas à chercher dans la FAQ et les forums
    • Merci d'utiliser les balises de code (# dans l'éditeur)
    • N'oubliez pas de vous servir des boutons , et

    S.N.A.F.U

  4. #4
    Candidat au Club
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    11
    Détails du profil
    Informations personnelles :
    Âge : 67
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Avril 2008
    Messages : 11
    Points : 4
    Points
    4
    Par défaut
    Je ne suis pas un pro de la programmation.
    Vous m'avez fait deux proposition que je ne sais pas appliquer.
    Pouvez vous détailler un peu plus ?

    L'idéal serait de calculer les points de la courbe directement dans l'image, et de n'avoir que les 8 ou 10 valeurs de base à passer.
    Mes essais montrent que dès que j'appelle une fonction dans le fichiers graph, cela ne marche pas.

Discussions similaires

  1. recharge de l'affichage d'une image(graphique)
    Par Titeuf82 dans le forum Servlets/JSP
    Réponses: 1
    Dernier message: 30/05/2008, 21h48
  2. Lier un fichier son à une image graphique
    Par dreanlin dans le forum Tcl/Tk
    Réponses: 5
    Dernier message: 05/07/2007, 16h51
  3. Problème graphique & calcul dans champ
    Par jacquesprogram dans le forum Access
    Réponses: 1
    Dernier message: 08/09/2006, 15h09
  4. [Image] Graphique dynamique
    Par navis84 dans le forum Bibliothèques et frameworks
    Réponses: 5
    Dernier message: 23/05/2006, 09h15
  5. excel, graphique, calcul nombre de dates
    Par debdev dans le forum Excel
    Réponses: 8
    Dernier message: 03/05/2006, 17h35

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo