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 :

Extension jpg généré


Sujet :

Langage PHP

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    10
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 10
    Points : 2
    Points
    2
    Par défaut Extension jpg généré
    Bonjour à tous,

    Je suis en train de développer avec l'aide d'un dev flash une mini-appli flash qui génère du jpg à la volée via php (pas encore optimisée)... http://www.buzzfactory.fr/2009/

    Mon problème vient du fait que le jpg généré a visiblement un souci d'extension ou de structure (il n'est reconnu par aucune appli).

    J'ai beau chercher et rechercher, je ne vois pas d'ou vient le pbm (je suis novice en php aussi),
    Quelqu'un aurait-il une piste ?
    Merci bcp toute aide éventuelle,

    Florent


    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
    <?php
    $largeur = $_POST['largeur'];
    $hauteur = $_POST['hauteur'];
    $pixels = $_POST['pixels'];
     
     
    /*
    echo 'L*l*6 = '.$largeur*$hauteur*6;
    echo 'chaine= '.strlen($pixels);
    */
    $image = imagecreatetruecolor($largeur,$hauteur);
     
    for($y=0;$y<$hauteur;$y++){
    	for($x=0;$x<$largeur;$x++){
    		// position du début de la séquence RRVVBB pour le pixel en cours
    		$i =(($y*$largeur) + $x) * 6;
     
    		// RVB
    		$r = hexdec(substr($pixels, $i, 2));
    		$v = hexdec(substr($pixels, $i+2, 2));
    		$b = hexdec(substr($pixels, $i+4, 2));
     
    		// création de la couleur
    		$colorid = imagecolorallocate($image,$r,$v,$b);
    		// écriture de la couleur dans l'image
    		imagesetpixel($image,$x,$y,$colorid);
    	}
    }
    header("Content-type: image/jpeg");
    imagejpeg($image,"",100);
    imagedestroy($image);
     
     
    ?>

  2. #2
    Membre confirmé Avatar de LeGilou
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    488
    Détails du profil
    Informations personnelles :
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations forums :
    Inscription : Octobre 2008
    Messages : 488
    Points : 531
    Points
    531
    Par défaut
    Bonjour Florent,

    Ca devrait faire quoi comme image ?
    Pour le moment, ca donne une image toute noire, mais dont la structure est correcte.

    Gillou.

  3. #3
    Candidat au Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    10
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 10
    Points : 2
    Points
    2
    Par défaut
    En fait, les pixels flash sont récupérés d'ici http://www.buzzfactory.fr/2009/ et envoyés sur ce php.
    Cela me fait une capture (pas centrée pr l'instant) et génère une image.
    (bizarre, chez moi ça ne fait pas d'écran noir ?)

    Mon problème vient du fait que si on enregistre l'image sous, le jpg n'est pas correct... (image.php)
    Si on la fait glisser sur le bureau, elle prend l'extension jpg mais est illisible

  4. #4
    Membre confirmé Avatar de LeGilou
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    488
    Détails du profil
    Informations personnelles :
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations forums :
    Inscription : Octobre 2008
    Messages : 488
    Points : 531
    Points
    531
    Par défaut
    ok.
    Peux tu nous donner un exemple de ce que tu récupères via $pixels.

    Gillou

  5. #5
    Candidat au Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    10
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 10
    Points : 2
    Points
    2
    Par défaut
    Voilà le code AS qui récupère les pixels (dsl il est un peu long)

    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
    import flash.display.BitmapData;
    import flash.geom.Rectangle;
    import flash.geom.Point;
     
    import flash.geom.Matrix;
    import flash.geom.ColorTransform;
    import mx.utils.Delegate;
     
    btn2.onRelease = Delegate.create(this,export);
     
    function export() {
     
    	var lv:LoadVars = new LoadVars();
     
     
    	// dÈtermine la zone de pixels ‡ envoyer
    	lv.largeur = zone._width;
    	lv.hauteur = zone._height
     
     
    	var xmin = Math.floor(zone._x);
    	var ymin = Math.floor(zone._y);
     
    	// on crÈe un bitmap ‡ la bonne taille
    	var bitmap1:BitmapData = new BitmapData(800, 500);
    	bitmap1.draw(this, new Matrix(), new ColorTransform() , "normal", new Rectangle(0, 0, 800, 500), false);
     
    	var bitmap:BitmapData = new BitmapData(lv.largeur, lv.hauteur);
    	bitmap.copyPixels(bitmap1,new Rectangle(xmin,ymin,lv.largeur,lv.hauteur), new Point(0,0));
     
    	lv.pixels = "";
    	for(var y = 0; y<lv.hauteur; y++){
    		for(var x =0; x<lv.largeur; x++){
     
    			var hexa = bitmap.getPixel(x,y).toString(16);
     
    			switch(hexa.length){
    				case 5:
    					hexa = '0'+hexa;
    					break;
    				case 4:
    					hexa = '00'+hexa;
    					break;
    				case 3:
    					hexa = '000'+hexa;
    					break;
    				case 2:
    					hexa = '0000'+hexa;
    					break;
    				case 1:
    					hexa = '00000'+hexa;
    					break;
    			}
    			lv.pixels+=hexa;
    		}
    	}
     
    	lv.send("http://www.buzzfactory.fr/2009/createjpg.php", "_blank", "POST");
     
    };

  6. #6
    Candidat au Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    10
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 10
    Points : 2
    Points
    2
    Par défaut
    En tt cas je viens de vérifier la capture semble fonctionner (du moins sur mac et firefox)...

    Par contre lors de l'enregister sous, il me propose : createjpg.php.html

  7. #7
    Membre confirmé Avatar de LeGilou
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    488
    Détails du profil
    Informations personnelles :
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations forums :
    Inscription : Octobre 2008
    Messages : 488
    Points : 531
    Points
    531
    Par défaut
    En fait, ce que je voudrais, c'est un exemple de valeur de
    $_POST['largeur']
    $_POST['hauteur']
    $_POST['pixels']

    Gillou

  8. #8
    Candidat au Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    10
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 10
    Points : 2
    Points
    2
    Par défaut
    Ah... ça se complique pour moi ;-) j'aurais du préciser dès le début que j'ai réalisé ce script avec l'aide précieuse d'un dev flash... ne sachant pas te répondre sur cette partie je vais lui demander

  9. #9
    Membre confirmé Avatar de LeGilou
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    488
    Détails du profil
    Informations personnelles :
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations forums :
    Inscription : Octobre 2008
    Messages : 488
    Points : 531
    Points
    531
    Par défaut
    Il faut juste ajouter ca en début de page

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    echo "<pre>";
    print_r($_POST);
    echo "</pre>";
    Le Flash envoit des valeurs dans la page PHP.
    Je veux juste savoir ce qu'il envoit

    Gillou

  10. #10
    Candidat au Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    10
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 10
    Points : 2
    Points
    2
    Par défaut
    Attention y'a du rvb à la chaine (je t'ai mis des ... pour ne pas afficher les millions de caractères) :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    Array
    (
        [pixels] => fffffffffffffffffffffffffffffffffffffffffffffffffffffffff9ffffacffff99ffff99ffff99ffff99ffff99ffff9fffffccffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffecffffc6ffffb2ffffb2ffffb2ffffccfffff3ffffffffffffffffffffffffffffffffffe6fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff3ffffdfffffb2ffffb2ffffb2ffffb2ffffb2ffffb2ffffb2ffffb2ffffb2ffffc6ffffecffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe6ffffd9ffffccffffb9ffffb2ffff99ffff99ffff99ffff99ffff99ffff99ffffacffffe6ffffecffffd9ffffccffffb2ffff9fffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffffb9ffffdffffff9fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff3ffffd9ffffbfffffa5ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffffdfffffbfffff99ffff99ffff99ffff99ffff99ffffacffffccffffccffffb9ffffecffffecffff9fffff99ffffdfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffffb2fffff3fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff   ..............fb2ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99ffff99fffff3ffffffffffffffffffffffffff000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
        [hauteur] => 292.5
        [largeur] => 292
    )

  11. #11
    Candidat au Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    10
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 10
    Points : 2
    Points
    2
    Par défaut
    Mais aussi

    Warning: Cannot modify header information - headers already sent by (output started at /home.29/b/u/z/buzzfact/www/2009/createjpgtest.php:6) in /home.29/b/u/z/buzzfact/www/2009/createjpgtest.php on line 35

    Warning: Cannot modify header information - headers already sent by (output started at /home.29/b/u/z/buzzfact/www/2009/createjpgtest.php:6) in /home.29/b/u/z/buzzfact/www/2009/createjpgtest.php on line 36

    Warning: Cannot modify header information - headers already sent by (output started at /home.29/b/u/z/buzzfact/www/2009/createjpgtest.php:6) in /home.29/b/u/z/buzzfact/www/2009/createjpgtest.php on line 37

    Warning: Cannot modify header information - headers already sent by (output started at /home.29/b/u/z/buzzfact/www/2009/createjpgtest.php:6) in /home.29/b/u/z/buzzfact/www/2009/createjpgtest.php on line 39

    Warning: Cannot modify header information - headers already sent by (output started at /home.29/b/u/z/buzzfact/www/2009/createjpgtest.php:6) in /home.29/b/u/z/buzzfact/www/2009/createjpgtest.php on line 41

    Warning: Cannot modify header information - headers already sent by (output started at /home.29/b/u/z/buzzfact/www/2009/createjpgtest.php:6) in /home.29/b/u/z/buzzfact/www/2009/createjpgtest.php on line 42

    Warning: imagejpeg(): supplied argument is not a valid Image resource in /home.29/b/u/z/buzzfact/www/2009/createjpgtest.php on line 44

    Warning: imagedestroy(): supplied argument is not a valid Image resource in /home.29/b/u/z/buzzfact/www/2009/createjpgtest.php on line 45

  12. #12
    Membre confirmé Avatar de LeGilou
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    488
    Détails du profil
    Informations personnelles :
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations forums :
    Inscription : Octobre 2008
    Messages : 488
    Points : 531
    Points
    531
    Par défaut
    Ca marche très bien....
    As tu d'autre code avant ou après ce que tu nous donnes ?

  13. #13
    Candidat au Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    10
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 10
    Points : 2
    Points
    2
    Par défaut
    Non, non, tout est dans le 1er post... d'ou mon pbm
    un AS+php comme celui de jeanphi marche très bien par ex (même s'il met les données ds un tab) http://jeanphiblog.media-box.net/dot...itmapdata2jpeg

    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
    <?php
    $lv = $_POST['tab'];
    $temp = explode(",",$lv);
    settype($temp[1],'integer');
    $sortie = imagecreatetruecolor(200,200);
    $k = 0;
    for($i=0; $i<200; $i++){
      for($j=0; $j<200; $j++){
        imagesetpixel($sortie,$j,$i,$temp[$k]);
        $k++;
      }
    }
    $lien = 'http://jxjxjxjxjx';
    $couleur_texte = imagecolorallocate($sortie, 255, 255, 255);
    imagestring($sortie, 1, 10, 190, $lien, $couleur_texte);
     
    @ob_end_clean();
    @ini_set('zlib.output_compression','Off');
     
    header('Pragma: public');
    header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
    header('Cache-Control: must-revalidate, pre-check=0, post-check=0, max-age=0');
     
    header('Content-Tranfer-Encoding: none');
     
    header('Content-Type: application/octetstream; name="buzz.jpg"');
    header('Content-Disposition: attachement; filename="buzz.jpg"');
     
    imagejpeg($sortie,"",100);
    imagedestroy($sortie);
     
    exit();
    ?>

  14. #14
    Membre confirmé Avatar de LeGilou
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    488
    Détails du profil
    Informations personnelles :
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations forums :
    Inscription : Octobre 2008
    Messages : 488
    Points : 531
    Points
    531
    Par défaut
    Pour faire des tests, j'ai remplacé les premières lignes de ton code par :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    $largeur = 200;
    $hauteur = 300;
    $pixels = "fffffffffffffffffe6ffffd9ffffccffffb9ffffb2ff..."
    et l'image s'affiche correctement.

    Il faut que ce code soit seul dans un fichier appelé par exemple "image.php".
    Ensuite, dans un autre fichier tu mets :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    <h1>Votre image</h1>
    <img src="image.php" />
    Gillou

  15. #15
    Candidat au Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    10
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 10
    Points : 2
    Points
    2
    Par défaut
    Merci bcp pour ton aide !! ... alors entre temps on a essayé ça, et ça marche (j'ai pas tout compris ;-)

    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
    <?php
    $largeur = $_POST['largeur'];
    $hauteur = $_POST['hauteur'];
    $pixels = $_POST['pixels'];
     
    $image = imagecreatetruecolor($largeur,$hauteur);
    for($y=0;$y<$hauteur;$y++){
    	for($x=0;$x<$largeur;$x++){
    		// position du début de la séquence RRVVBB pour le pixel en cours
    		$i =(($y*$largeur) + $x) * 6;
     
    		// RVB
    		$r = hexdec(substr($pixels, $i, 2));
    		$v = hexdec(substr($pixels, $i+2, 2));
    		$b = hexdec(substr($pixels, $i+4, 2));
     
    		// création de la couleur
    		$colorid = imagecolorallocate($image,$r,$v,$b);
    		// écriture de la couleur dans l'image
    		imagesetpixel($image,$x,$y,$colorid);
    	}
    }
     
    // un nom unique
    $filename = time().'.jpg';
    imagejpeg($image,$filename,100);
    imagedestroy($image);
     
    ?>
    <html>
    <img src="<?php echo $filename;?>" alt=""/>
    </html>

Discussions similaires

  1. [Formulaire] Input file, voir uniquement extensions jpg
    Par Sayrus dans le forum Balisage (X)HTML et validation W3C
    Réponses: 3
    Dernier message: 02/07/2007, 11h12
  2. Différence entre les extensions '.JPG' et '.jpg'
    Par ecarbill dans le forum Général JavaScript
    Réponses: 5
    Dernier message: 07/06/2007, 15h20
  3. [Upload] Changer une extension JPG en jpg
    Par svan1812 dans le forum Langage
    Réponses: 6
    Dernier message: 21/02/2007, 21h32
  4. [Blend beta 1][VS Extension WPF CTP 11/06] VS ne lit pas le code généré par Blend
    Par FRED.G dans le forum Windows Presentation Foundation
    Réponses: 4
    Dernier message: 09/12/2006, 17h50
  5. [Fichier] Verification de l'extension jpg
    Par Taz_8626 dans le forum Langage
    Réponses: 9
    Dernier message: 13/04/2006, 10h36

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