- <?php
- function rotation($img,$degres)
- {
- if(file_exists($img))
- {
- $image = getimagesize($img);
- $image_type = $image['2'];
-
- // création de l'image selon son extension (type) :
- if($image_type == "1") $source = imagecreatefromgif($img);
- if($image_type == "2") $source = imagecreatefromjpeg($img);
- if($image_type == "3") $source = imagecreatefrompng($img);
- if($image_type == "6") $source = imagecreatefromwbmp($img);
-
- //rotation de l'image
- $rotation = imagerotate($source,$degres,-1) or die("Erreur lors de la rotation de ".$file);
- //Le -1 permet de remplir les zones vides avec du transparent
-
- // sauvegarde de l'image (selon son type :
- if($image_type == "1") imagegif($rotation,$img);
- if($image_type == "2") imagejpeg($rotation,$img);
- if($image_type == "3") imagepng($rotation,$img);
- if($image_type == "6") imagewbmp($rotation,$img);
- }
- }
-
- //exemple d'utilisation :
-
- rotation('ma_photo12.jpg','180');
-
- // : tournera ma_photo12.jpg à 180°
- //ATTENTION: si l'image n'est pas dans le même dossier que le
- //fichier php, il faut le spécifié. Si ma_photo12.jpg était dans un
- //dossier photo, par exemple, il aurait fallu écrire:
-
- rotation('photo/ma_photo12.jpg','180');
- ?>
<?php
function rotation($img,$degres)
{
if(file_exists($img))
{
$image = getimagesize($img);
$image_type = $image['2'];
// création de l'image selon son extension (type) :
if($image_type == "1") $source = imagecreatefromgif($img);
if($image_type == "2") $source = imagecreatefromjpeg($img);
if($image_type == "3") $source = imagecreatefrompng($img);
if($image_type == "6") $source = imagecreatefromwbmp($img);
//rotation de l'image
$rotation = imagerotate($source,$degres,-1) or die("Erreur lors de la rotation de ".$file);
//Le -1 permet de remplir les zones vides avec du transparent
// sauvegarde de l'image (selon son type :
if($image_type == "1") imagegif($rotation,$img);
if($image_type == "2") imagejpeg($rotation,$img);
if($image_type == "3") imagepng($rotation,$img);
if($image_type == "6") imagewbmp($rotation,$img);
}
}
//exemple d'utilisation :
rotation('ma_photo12.jpg','180');
// : tournera ma_photo12.jpg à 180°
//ATTENTION: si l'image n'est pas dans le même dossier que le
//fichier php, il faut le spécifié. Si ma_photo12.jpg était dans un
//dossier photo, par exemple, il aurait fallu écrire:
rotation('photo/ma_photo12.jpg','180');
?>