tiens un exemple de redim à l'affichage:
<?php
/*La fonction fctaffichimage($W_max, $H_max, $img_Src)
La fonction affiche : width="..." height="..."
Les paramètres
- $W_max : LARGEUR maxi d'affichage --> ou 0
- $H_max : HAUTEUR maxi d'affichage --> ou 0
- $img_Src : chemin+NOM de l'image Source
- si $W_max = 0 --> LARGEUR auto
- si $H_max = 0 --> HAUTEUR auto
*/
///// Utilisation :
// FONCTION de redimensionnement "a l'affichage"
// -----------------------------------------------------------------------------------------------------
// fonction de redimensionnement A L'AFFICHAGE
// -----------------------------------------------------------------------------------------------------
// La FONCTION : fctaffichimage($W_max, $H_max, $img_Src)
// Les parametres :
// - $W_max : LARGEUR maxi finale ----> ou 0 : largeur libre
// - $H_max : HAUTEUR maxi finale ----> ou 0 : hauteur libre
// - $img_Src : NOM de l image Source
// -----------------------------------------------------------------------------------------------------
// Affiche : width="..." height="..." pour la balise img
// -----------------------------------------------------------------------------------------------------
function fctaffichimage($W_max, $H_max, $img_Src) {
// ------------------------------------------------------------------
// Lit les dimensions de l'image
$img_size = GetImageSize($img_Src);
$W_Src = $img_size[0]; // largeur
$H_Src = $img_size[1]; // hauteur
// ------------------------------------------------------------------
// Teste les dimensions tenant dans la zone
$H_test = round(($W_max / $W_Src) * $H_Src);
$W_test = round(($H_max / $H_Src) * $W_Src);
// ------------------------------------------------------------------
// Si $H_max non précisé (0)
if(!$H_max) { $H_max = $H_test; }
// Sinon si $W_max non précisé (0)
elseif(!$W_max) { $W_max = $W_test; }
// Sinon teste quel redimensionnement tient dans la zone
elseif($H_test > $H_max) { $W_max = $W_test; }
else { $H_max = $H_test; }
// ------------------------------------------------------------------
// (procedure : ne retourne aucune valeur mais ...)
// AFFICHE les dimensions optimales
// Affiche : width="..." height="..."
echo ' width="'.$W_max.'" height="'.$H_max.'"';
}
?>
<html>
<img alt="" src="IMG_0677.JPG" <?php fctaffichimage(200, 300, 'IMG_0677.JPG') ?> />
</html>