<html>
<body bgcolor="#FFFFFF" text="#000000">
<?php
# Récupération des paramètres actuels ou par défaut
if ($mode != 2) $mode = 1;
if ($acti != 1) $acti = 0;
if (($coef<=0) || ($coef>100)) $coef = 0.5;
if (($sizx<=0) || ($sizx>2000)) $sizx = 0;
if (($sizy<=0) || ($sizy>2000)) $sizy = 0;
$path = (!empty($path)) ? stripSlashes($path) : "./";
$mesg = "";
# Control la validité des nouvelles dimensions
$size_error = 0;
if (($mode==2) && ($sizx==0) && ($sizy==0))
{ $size_error=1; $mesg.="<br>Vous devez spécifier au moins sizx ou sizy si vous n'utilisez pas le coeff !\n"; }
# Control la validité du répertoire source et destination
$path_error = 0;
if (substr($path, -1) != "/") $path = $path . "/";
if (!is_dir($path)) { $path_error=1; $mesg.="<br>Le chemin '$path' n'est pas un répertoire !\n"; }
else {
if (!is_readable($path)) { $path_error=1; $mesg.="<br>Le chemin '$path' n'est pas accessible en lecture !\n"; }
if (!is_writable($path)) { $path_error=1; $mesg.="<br>Le chemin '$path' n'est pas accessible en écriture !\n"; }
}
# Récupération des images à traiter dans le répertoire
$imagelist = array ();
if ($path_error == 0) {
$handle = opendir($path);
while ($file = readdir($handle))
if (preg_match("/^(.+\.jpg)$/i", $file, $match))
if (substr($match[1], 0, 3) != "TN_")
if (!in_array($match[1], $imagelist)) array_push($imagelist, $match[1]);
closedir($handle);
ksort($imagelist);
}
?>
<div align="center">
<?php print $mesg; ?>
<form name="frm" method=POST>
<div align="center">
<table border=0 cellpadding=0 cellspacing=5 bgcolor="#CCCCCC">
<tr>
<td colspan=2 align="center">
path (relatif) :
<input type="textfield" name="path" value="<?php echo $path; ?>" size=32>
</td>
</tr>
<tr>
<td>
<?php print "<input type='radio' name='mode' value=2 ".($mode==2?"checked":"").">"; ?>
sizx : <input type="textfield" name="sizx" value="<?php echo $sizx; ?>" size=5>
sizy : <input type="textfield" name="sizy" value="<?php echo $sizy; ?>" size=5>
</td>
<td>
<?php print "<input type='radio' name='mode' value=1 ".($mode==1?"checked":"").">"; ?>
coef : <input type="textfield" name="coef" value="<?php echo $coef; ?>" size=5>
</td>
</tr>
<tr>
<td>
<?php print "<input type='checkbox' name='acti' value=1 ".($acti==1?"checked":"").">"; ?>
activer le resize des images
</td>
<td align="right"><input type="submit" value="valider"></td>
</tr>
</table></div>
</form></div>
<?php
# Affichage de la liste des fichiers à traiter
print "<br>Liste des images à traiter :<ul>\n";
for ($i=0; $i<count($imagelist); $i++)
print "<li><a href='$path$imagelist[$i]'>$imagelist[$i]</a></li>\n";
print "</ul>\n";
?>
<div align="center">
<table border=1 cellpadding=5 cellspacing=0 bgcolor="#CCCCCC">
<tr>
<?php
if (($acti==1) && ($path_error==0) && ($size_error==0)) {
for ($i=0; $i<count($imagelist); $i++) {
$src = @imagecreatefromjpeg($path.$imagelist[$i]);
if ($src) {
# récupération de la taille de l'image source
$srcW = imagesx($src);
$srcH = imagesy($src);
# calcul des dimensions de l'image de destination
if ($mode==1) {
$dstW = floor($coef * $srcW);
$dstH = floor($coef * $srcH);
} else {
$dstW = ($sizx>0)?$sizx:floor($sizy*$srcW/$srcH);
$dstH = ($sizy>0)?$sizy:floor($sizx*$srcH/$srcW);
}
# création de la nouvelle image redimensionnée
$dst = @imagecreatetruecolor($dstW, $dstH);
# imagecopyresized($dst, $src, 0, 0, 0, 0, $dstW, $dstH, $srcW, $srcH);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $dstW, $dstH, $srcW, $srcH);
# sauvegarde du fichier de la nouvelle image
$file = "TN_".$imagelist[$i];
imagejpeg($dst, $path.$file, 100);
imagedestroy($dst);
imagedestroy($src);
# affichage de l'image créée dans la page html
print "<td align='center'><a href='$path$file'><img src='$path$file' border=1></a>";
print "<br>$file<br>[$dstW x $dstH]</td>\n";
if (($i+1)%4==0) print "</tr><tr>\n";
} else { print "<br>Error loading image !\n"; }
}
}
?>
</tr>
</table>
</div>
</body>
</html>