» Redimensionner ses photos
Rédigé par :
demontant
Le : 14/05/2005 à 18:58
Hits : 6093
Source pour redimensionner ces photos, les afficher grâce à une requête Mysql.
article_16.php
<?php
// ------------------------------------------------------------------------- //
// Redimensionner ses photos //
// ------------------------------------------------------------------------- //
// 14/05/2005 18:58:09 par Olivier Demontant (armed@free.fr) //
// ------------------------------------------------------------------------- //
// http://www.gphp.net/articles,16.php //
// ------------------------------------------------------------------------- //
//Connexion à MySQL
$hostname = "localhost";
$database = "srciptphp";
$username = "root";
$password = "";
$db = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database, $db);
$query = "SELECT * FROM foto ORDER BY id ASC";
$result = mysql_query($query, $db) or die(mysql_error());
$row = mysql_fetch_assoc($result);
//Fonction pour reduire l'image
function gallery($photo, $reduc)
{
$taille = getimagesize($photo);
$l_vlign = floor(($taille[0]*$reduc)/100);
$h_vlign = floor(($taille[1]*$reduc)/100);
echo "<img src='$photo' height='$h_vlign' width='$l_vlign' border='0'><br>";
}
//On affiche l'image reduite avec une boucle si on en a plusieurs.
do {
$photo = $row['photo'];
echo gallery($photo, 25);
} while ($row = mysql_fetch_assoc($result));
//On ferme MySQL
mysql_close();
?>
article_16.sql
## ------------------------------------------------------------------------- ##
## Redimensionner ses photos ##
## ------------------------------------------------------------------------- ##
## Le 14/05/2005 18:58:09 par Olivier Demontant (armed@free.fr) ##
## ------------------------------------------------------------------------- ##
## http://www.gphp.net/articles,16.php ##
## ------------------------------------------------------------------------- ##
CREATE TABLE foto (
id int(11) NOT NULL auto_increment,
photo varchar(150) NOT NULL default '',
PRIMARY KEY (id)
);
» Commentaires
Vous devez être connecté en tant que Membre pour pouvoir poster un commentaire, Inscrivez vous ici !