Invité
Invité n'ayant pas de compte PHPfrance
01 sept. 2005, 20:05
Voici le code
mysql_select_db($database_db_bastin, $db_bastin);
$query_last_id = "SELECT MAX(id_tourisme) FROM tourisme";
$last_id = mysql_query($query_last_id, $db_bastin) or die(mysql_error());
$row_last_id = mysql_fetch_assoc($last_id);
$totalRows_last_id = mysql_num_rows($last_id);
if(($_POST) && ($_FILES['image']['type'] == "image/jpeg" OR $_FILES['image']['type'] == "image/pjpeg") && $_FILES['image']['error'] == 0) {
$nom_fichier=$row_last_id['MAX(id_tourisme)']."_T.jpg";
$nom_temp = $_FILES['image']['tmp_name'];
$dossier = "../img/up/tourisme/photo/";
move_uploaded_file($nom_temp,$dossier.$nom_fichier);
//recalibration image
$chemin = $dossier.$nom_fichier;
//echo $chemin; exit;
$max_width = 500;
$max_height = 420;
$size=getimagesize($chemin);
$width=$size[0];
$height=$size[1];
print_r($size);
$x_ratio=$max_width/$width;
$y_ratio=$max_height/$height;
if (($width <= $max_width) && ($height <= $max_height))
{
$tn_width=$width;
$tn_height=$height;
}
else if (($x_ratio * $height) < $max_height)
{
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
}
else {
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}
$src = imagecreatefromjpeg($chemin);
$dst = imagecreatetruecolor($tn_width,$tn_height);
//imagecreatetruecolor
imagecopyresized($dst,$src,0,0,0,0,$tn_width,$tn_height,$width,$height);
//header("content-type: image/jpeg");
$couleurrouge = imagecolorallocate($dst, 125, 125, 125);
imagestring($dst, 2, 2, 2, "", $couleurrouge);
//imagejpeg($dst, "up/photo/minimenu.jpg", -1); //écrit l'image réduite sur le serveur
imagejpeg($dst, $chemin, 80); //renvoie l'image au navigateur
imagedestroy($src);
imagedestroy($dst);
//fin recalibration image
//création vignette
//echo $chemin; exit;
$max_width = 85;
$max_height = 85;
$size=getimagesize($chemin);
$width=$size[0];
$height=$size[1];
$x_ratio=$max_width/$width;
$y_ratio=$max_height/$height;
if (($width <= $max_width) && ($height <= $max_height))
{
$tn_width=$width;
$tn_height=$height;
}
else if (($x_ratio * $height) < $max_height)
{
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
}
else {
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}
$src = imagecreatefromjpeg($chemin);
$dst = imagecreatetruecolor($tn_width,$tn_height);
//imagecreatetruecolor
imagecopyresized($dst,$src,0,0,0,0,$tn_width,$tn_height,$width,$height);
//header("content-type: image/jpeg");
$couleurrouge = imagecolorallocate($dst, 125, 125, 125);
//imagestring($dst, 2, 2, 2, "MON NOM COPYRIGHT", $couleurrouge); //AJOUT COPYRIGHT__
//imagejpeg($dst, "up/vignette/minimenu.jpg", -1); //écrit l'image réduite sur le serveur
$dossier="../img/up/tourisme/vignette/";
$chemin = $dossier.$nom_fichier;
imagejpeg($dst, $chemin, 80); //renvoie l'image au navigateur
imagedestroy($src);
imagedestroy($dst);
//fin création vignette