1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| function compresserImage($source, $dest, $quality) { // quality 0 à 100
//echo"<br />source : $source<br />";
//echo"<br />dest : $dest<br />";
$info = getimagesize($source);
echo"info : <br />"; print_r($info); echo"<br />";
$fileSize=filesize($source);
$fileSizeKO=strval(round($fileSize/1024))." Ko";
echo"taille $source = $fileSizeKO.";
// Save orientation image source ($source)
if ($info['mime'] == 'image/jpeg') {
$exif = exif_read_data($source,'tmp_name');
if (!empty($exif['Orientation'])) {
$file_orientation = $exif['Orientation'];
}
//echo"<br />file_orientation : $file_orientation<br />";
// Check orientation of image source ($source) and rotate si nécessaire
//if ($file_orientation > 1) {
$image = imagecreatefromjpeg($source);
if (in_array($file_orientation, [3, 4])) {
$image = imagerotate($image, 180, 0);
}
if (in_array($file_orientation, [5, 6])) {
$image = imagerotate($image, -90, 0);
}
if (in_array($file_orientation, [7, 8])) {
$image = imagerotate($image, 90, 0);
}
if (in_array($file_orientation, [2, 5, 7, 4])) {
imageflip($image, IMG_FLIP_HORIZONTAL);
}
//}
}
elseif ($info['mime'] == 'image/gif') {
$image = imagecreatefromgif($source);
}
elseif ($info['mime'] == 'image/png') {
$image = imagecreatefrompng($source);
}
imagejpeg($image, $dest, $quality);
} |
Partager