Merci.
Code : Tout sélectionner
$data = mysql_real_escape_string($photos[0]['photo_blob']);
$image = imagecreatefromstring($data);
Tu as surement raison mais le premier tutorial clair que j'ai trouvé pour l'upload d'image en php, le faisait de cette façon. Je changerai peut être plus tard, pour l'instant j'aimerai déja avoir une appli fonctionnel. Et puis il y a le coté pratique de la suppression en cascade des images lorsque l'on supprime l'objet sur lequel l'image est rataché, alors qu'avec le stockage sur le système de fichier il aurai fallu : 1 - Supprimer l'objet en base. 2 - Supprimer le fichier. Sa demande peut etre pas plus que ça a faire, mais n'étant pas un pros du php, j'ai préféré tout stocker en base.Quant au fait de stocker ton image directement en base, à moins d'avoir besoin de travailler sur des formes, des couleurs, de la luminosité, etc., j'ai pas encore trouvé de raison vallable de surcharger sa base de données
header('Content-Type: '.$photo['photo_type']);
header('Content-Type: '.$photo['photo_type']);
//$image = imagecreatefromstring($photo['photo_blob']);
$ext = explode("/", $photo['photo_type']);
$source = call_user_func('createimagefrom'.$ext[1], $photo['photo_blob']);
call_user_func('image'.$ext[1], $source);
Celui ci fonctionne et affiche l'image pourtant je fais à peu prés la même chose non ? Enfin j'aimerai comprendre la différence et comment faire fonctionner ceci ?
header('Content-Type: '.$photo['photo_type']);
$image = imagecreatefromstring($photo['photo_blob']);
$ext = explode("/", $photo['photo_type']);
//$source = call_user_func('createimagefrom'.$ext[1], $photo['photo_blob']);
call_user_func('image'.$ext[1], $image);
//header('Content-Type: '.$photo['photo_type']);
$source = imagecreatefromstring($photo['photo_blob']);
list($width_src, $height_src) = getimagesize($source);
if ($width && ($width_src < $height_src)) {
$width = ($height / $height_src) * $width_src;
} else {
$height = ($width / $width_src) * $height_src;
}
echo "width: ";
echo $width;
echo "\n";
echo "height: ";
echo $height;
exit;
Warning: getimagesize() [function.getimagesize]: Unable to access Resource id #5 in /opt/coolstack/apache2/htdocs/Website/image.php on line 17
Warning: getimagesize(Resource id #5) [function.getimagesize]: failed to open stream: No such file or directory in /opt/coolstack/apache2/htdocs/Website/image.php on line 17
Warning: Division by zero in /opt/coolstack/apache2/htdocs/Website/image.php on line 21
width: 200 height: 0
//récupère les infos en base.
header('Content-Type: '.$photo['photo_type']);
$source = imagecreatefromstring($photo['photo_blob']);
$width_src = imagesx($source);
$height_src = imagesy($source);
if ($width && ($width_src < $height_src)) {
$width = ($height / $height_src) * $width_src;
} else {
$height = ($width / $width_src) * $height_src;
}
$ext = explode("/", $photo['photo_type']);
$destination = imagecreatetruecolor ($width, $height) or die ("Erreur pour créer l'image");
// on créé un cadre autour de la miniature
$blanc = imagecolorallocate ($destination, 255, 255, 255);
$gris[0] = imagecolorallocate ($destination, 69, 69, 69);
$gris[1] = imagecolorallocate ($destination, 82, 82, 82);
$gris[2] = imagecolorallocate ($destination, 97, 97, 97);
$gris[3] = imagecolorallocate ($destination, 107, 107, 107);
$gris[4] = imagecolorallocate ($destination, 120, 120, 120);
$gris[5] = imagecolorallocate ($destination, 134, 134, 134);
$gris[6] = imagecolorallocate ($destination, 145, 145, 145);
for ($i=0; $i<7; $i++) {
imagefilledrectangle($destination, $i, $i, $width-$i, $height-$i, $gris[$i]);
}
// créé la miniature : attention fonction lourde
imagecopyresampled($destination, $source, 8, 8, 0, 0, $width-(2*8), $height-(2*8), $width_src, $height_src);
call_user_func('image'.$ext[1], $destination);
imagedestroy($source);
imagedestroy($destination);
Voici comment appeler la fonction :
Code : Tout sélectionner
<img src="image.php?id=<?php echo $photos[0]['photo_id']; ?>"/>
qui s'affiche en haut à gauche de ce sujet