Site web des serveurs MineTest Juneland
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

96 lines
1.7 KiB

<?php
require_once('config.php');
if (!isset($_GET['thumbWidth']) or !in_array($_GET['thumbWidth'], $acceptedWidth)) {
die('Cette taille n\'est pas disponible.');
}
$jpegQuality = 75;
$imgFilename = $_GET['filename'];
$imgName = substr($imgFilename, 0, strrpos($imgFilename, '.'));
$origImgDir = 'img/';
$origImgPath = $origImgDir . $imgName;
if (file_exists($origImgPath . '.png')) {
$origImgExt = 'png';
} elseif (file_exists($origImgPath . '.jpg') or file_exists($origImgPath . '.jpeg')) {
$origImgExt = 'jpg';
} else {
die('L\'image source n\'a pas été trouvée.');
}
$origImgPath .= '.' . $origImgExt;
list($origImgWidth, $origImgHeight, $origImgType) = getimagesize($origImgPath);
switch ($origImgType) {
case 1:
$origImgType = 'GIF';
break;
case 2:
$origImgType = 'JPEG';
break;
case 3:
$origImgType = 'PNG';
break;
default:
die('Le type de l\'image originale n\'a pas été reconnu.');
}
$thumbWidth = intval($_GET['thumbWidth']);
$thumbHeight = round($thumbWidth / $origImgWidth * $origImgHeight);
$thumb = imagecreatetruecolor($thumbWidth, $thumbHeight);
if ($origImgType == 'JPEG') {
$origImg = imagecreatefromjpeg($origImgPath);
} elseif ($origImgType == 'PNG') {
$origImg = imagecreatefrompng($origImgPath);
}
// Redimensionnement
imagecopyresampled(
$thumb,
$origImg,
0, 0,
0, 0,
$thumbWidth, $thumbHeight,
$origImgWidth, $origImgHeight
);
$thumbDir = 'thumbs/' . $thumbWidth . 'w/';
$thumbPath = $thumbDir . $imgName . $thumbExt;
if (!is_dir($thumbDir)) {
mkdir($thumbDir, 0777);
}
header('Content-Type: image/jpeg');
imagejpeg($thumb, $thumbPath, $jpegQuality);
imagejpeg($thumb);
imagedestroy($thumb, $origImg);