Image affichée mais pas enregistrée

raedgates - 14 août 2012 à 01:31
cs_Mcjo Messages postés 403 Date d'inscription dimanche 12 août 2001 Statut Membre Dernière intervention 3 septembre 2012 - 15 août 2012 à 11:05
Salut
J'ai un SWF dans ma page HTML qui permet de prendre une photo avec la Webcam. Une fois la photo prise il renvoi vers une page PHP ou il ne fais que afficher la photo . Je voudrai que la photo soit enregistrer sur le serveur mais je ne sait pas comment m'y prendre. Aider moi SVP
NB:je travail en local

Voici le code la page cible du Flash

?php
error_reporting(0);
/**
* Get the width and height of the destination image
* from the POST variables and convert them into
* integer values
*/
$w = (int)$_POST['width'];
$h = (int)$_POST['height'];

// create the image with desired width and height

$img = imagecreatetruecolor($w, $h);

// now fill the image with blank color
// do you remember i wont pass the 0xFFFFFF pixels
// from flash?
imagefill($img, 0, 0, 0xFFFFFF);

$rows = 0;
$cols = 0;

// now process every POST variable which
// contains a pixel color
for($rows = 0; $rows < $h; $rows++){
// convert the string into an array of n elements
$c_row = explode(",", $_POST['px' . $rows]);
for($cols = 0; $cols < $w; $cols++){
// get the single pixel color value
$value = $c_row[$cols];
// if value is not empty (empty values are the blank pixels)
if($value != ""){
// get the hexadecimal string (must be 6 chars length)
// so add the missing chars if needed
$hex = $value;
while(strlen($hex) < 6){
$hex = "0" . $hex;
}
// convert value from HEX to RGB
$r = hexdec(substr($hex, 0, 2));
$g = hexdec(substr($hex, 2, 2));
$b = hexdec(substr($hex, 4, 2));
// allocate the new color
// N.B. teorically if a color was already allocated
// we dont need to allocate another time
// but this is only an example
$test = imagecolorallocate($img, $r, $g, $b);
// and paste that color into the image
// at the correct position
imagesetpixel($img, $cols, $rows, $test);
}
}
}

// print out the correct header to the browser
header("Content-type:image/jpeg");
// display the image
imagejpeg($img, "pix/test.png", 90);
imagejpeg($img, "", 90);
?>

1 réponse

cs_Mcjo Messages postés 403 Date d'inscription dimanche 12 août 2001 Statut Membre Dernière intervention 3 septembre 2012 2
15 août 2012 à 11:05
Vérifie que le répertoire pix existe.
Remplace au début de ton script :
error_reporting(0);
par
error_reporting(E_ALL ^ E_NOTICE);

Commente les lignes :
header("Content-type:image/jpeg");
et imagejpeg($img, "", 90); (au passage la syntaxe correcte est imagejpeg($img, null, 90);)

Tu devrais avoir un warning sur la ligne :
imagejpeg($img, "pix/test.png", 90);
0
Rejoignez-nous