- function fonc_redim($img,$taille)
- {
- $image_dim = getimagesize($img);
-
- //respect du ratio hauteur/largeur pour le calcul des nouvelles dimensions
- if($image_dim[0] > $image_dim[1]) // x est plus grand que y
- {
- $new_x = $taille;
- $new_y = $image_dim[1]/($image_dim[0]/$taille);
- }
- else
- {
- if($image_dim[0] < $image_dim[1]) // y est plus grand que x
- {
- $new_y = $taille;
- $new_x = $image_dim[0]/($image_dim[1]/$taille);
- }
- else // x == y
- {
- $new_x = $taille;
- $new_y = $taille;
- }
- }
-
- Header("Content-type : img/jpeg");
- $old_img = imagecreatefromjpeg($img);
-
- $chaine = substr($img,0,-4);//enléve les 4 derniers caractères ( ".JPG" )
- $chaine.="_mini.jpg";
-
- //verification
- if (!$old_img)
- {
- $im = imagecreate(150, 30); // Création d'une image blanche
- $bgc = imagecolorallocate($old_img, 255, 255, 255);
- $tc = imagecolorallocate($old_img, 0, 0, 0);
- imagefilledrectangle($old_img, 0, 0, 150, 30, $bgc);
- // Affichage d'un message d'erreur
- imagestring($old_img, 1, 5, 5, "Erreur de chargement de l'image $img", $tc);
- return $old_img;
- }
-
- if(!file_exists($chaine))
- {
- $new_img = imageCreatetruecolor($new_x, $new_y);
- imagecopyresampled ($new_img, $old_img,0,0,0,0,$new_x,$new_y,$image_dim[0],$image_dim[1]);
- imagejpeg($new_img,$chaine);
- imagedestroy($new_img);
- }
-
-
- imagedestroy($old_img);
-
- print "<FORM>";
- //popup qui va afficher l'image
- print "<INPUT TYPE =\"image\" src=\"".$chaine."\" onClick=\"open('image.php?im=".$img."', 'new', 'toolbar=no,location=no, directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes')\">";
-
- print "</FORM>";
- }
-
-
- ////////////////// image.php ////////////////////////////////////////////////////////
-
- <html>
- <head><title></title></head>
- <body>
- <?php
-
- $img = $_REQUEST["im"];
-
- ?>
-
- <form>
- <input type="image" src="<? print $img?>" onclick="self.close()">
- </form>
-
- </body>
- </html>
function fonc_redim($img,$taille)
{
$image_dim = getimagesize($img);
//respect du ratio hauteur/largeur pour le calcul des nouvelles dimensions
if($image_dim[0] > $image_dim[1]) // x est plus grand que y
{
$new_x = $taille;
$new_y = $image_dim[1]/($image_dim[0]/$taille);
}
else
{
if($image_dim[0] < $image_dim[1]) // y est plus grand que x
{
$new_y = $taille;
$new_x = $image_dim[0]/($image_dim[1]/$taille);
}
else // x == y
{
$new_x = $taille;
$new_y = $taille;
}
}
Header("Content-type : img/jpeg");
$old_img = imagecreatefromjpeg($img);
$chaine = substr($img,0,-4);//enléve les 4 derniers caractères ( ".JPG" )
$chaine.="_mini.jpg";
//verification
if (!$old_img)
{
$im = imagecreate(150, 30); // Création d'une image blanche
$bgc = imagecolorallocate($old_img, 255, 255, 255);
$tc = imagecolorallocate($old_img, 0, 0, 0);
imagefilledrectangle($old_img, 0, 0, 150, 30, $bgc);
// Affichage d'un message d'erreur
imagestring($old_img, 1, 5, 5, "Erreur de chargement de l'image $img", $tc);
return $old_img;
}
if(!file_exists($chaine))
{
$new_img = imageCreatetruecolor($new_x, $new_y);
imagecopyresampled ($new_img, $old_img,0,0,0,0,$new_x,$new_y,$image_dim[0],$image_dim[1]);
imagejpeg($new_img,$chaine);
imagedestroy($new_img);
}
imagedestroy($old_img);
print "<FORM>";
//popup qui va afficher l'image
print "<INPUT TYPE =\"image\" src=\"".$chaine."\" onClick=\"open('image.php?im=".$img."', 'new', 'toolbar=no,location=no, directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes')\">";
print "</FORM>";
}
////////////////// image.php ////////////////////////////////////////////////////////
<html>
<head><title></title></head>
<body>
<?php
$img = $_REQUEST["im"];
?>
<form>
<input type="image" src="<? print $img?>" onclick="self.close()">
</form>
</body>
</html>