Last active
April 6, 2020 15:23
-
-
Save eurowebpage/3286be4e27bd9586c6e371f6271b3d04 to your computer and use it in GitHub Desktop.
redimensionner-sans-deformer-l-images-fonction-fct-affich-image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/*---------------------------------------------------------------*/ | |
/* Redimensionner une image sans distorsion fct_affich_image | |
/*---------------------------------------------------------------*/ | |
function fct_affich_image($Wmax, $Hmax, $img_Src) { | |
// Lit les dimensions de l'image | |
$sizeimg = GetImageSize($img_Src); | |
$Src_W = $sizeimg[0]; // largeur | |
$Src_H = $sizeimg[1]; // hauteur | |
// Teste les dimensions tenant dans la zone | |
$test_H = round(($Wmax / $Src_W) * $Src_H); | |
$test_W = round(($Hmax / $Src_H) * $Src_W); | |
// Si Height final non précisé (0) | |
if(!$Hmax) $Hmax = $test_H; | |
// Sinon si Width final non précisé (0) | |
elseif(!$Wmax) $Wmax = $test_W; | |
// Sinon teste quel redimensionnement tient dans la zone | |
elseif($test_H>$Hmax) $Wmax = $test_W; | |
else $Hmax = $test_H; | |
// (procédure : ne retourne aucune valeur mais ...) | |
// AFFICHE les dimensions optimales | |
echo 'width='.$Wmax.' height='.$Hmax; | |
} | |
?> | |
// ---------------------------- HTML Body Affichage ------------------------------------------------ | |
<img src="img/getimagesize.jpg" alt="image redimensionnée" title="image redimensionnée" <?php fct_affich_image(200, 200, 'img/getimagesize.jpg') ?>> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment