Salut, sa fait 4 heures de temps que je gosses apprais ce code:
function imageResize ($fichier_dossier, $fileName, $KEEP_PROPORTIONS) {
$aProportions = array ('DO_NOT_KEEP_PROPORTIONS', 'KEEP_PROPORTIONS_ON_WIDTH', 'KEEP_PROPORTIONS_ON_HEIGHT', 'KEEP_PROPORTIONS_ON_BIGGEST', 'KEEP_PROPORTIONS_ON_SMALLEST');
if (!file_exists ($fileName) || !is_array ($KEEP_PROPORTIONS) || empty ($KEEP_PROPORTIONS)) {
return false;
} else {
$aImg = @getimagesize ($fileName);
if (false === $aImg) {
return false;
} else {
$aTypes = array (1 => 'gif', 2 => 'jpeg', 3 => 'png');
if (!in_array ($aImg[2], array_keys ($aTypes))) {
return false;
} else {
if (!in_array ($KEEP_PROPORTIONS[0], $aProportions)) {
return false;
}
$iCmpt = count ($KEEP_PROPORTIONS);
if (!empty ($KEEP_PROPORTIONS) && is_array ($KEEP_PROPORTIONS) && ($iCmpt >= 2) && is_int ($KEEP_PROPORTIONS[1])) {
switch ($KEEP_PROPORTIONS[0]) {
case 'KEEP_PROPORTIONS_ON_WIDTH' :
$width = $KEEP_PROPORTIONS[1];
$height = round ($aImg[1] / (round ($aImg[0]/$KEEP_PROPORTIONS[1])));
break;
case 'KEEP_PROPORTIONS_ON_HEIGHT' :
$height = $KEEP_PROPORTIONS[1];
$width = round ($aImg[0]/ (round ($aImg[1]/$KEEP_PROPORTIONS[1])));
break;
case 'KEEP_PROPORTIONS_ON_BIGGEST' :
if ($aImg[0] >= $aImg[1]) {
$width = $KEEP_PROPORTIONS[1];
$height = round ($aImg[1] / (round ($aImg[0]/$KEEP_PROPORTIONS[1])));
} else {
$height = $KEEP_PROPORTIONS[1];
$width = round ($aImg[0] / (round ($aImg[1]/$KEEP_PROPORTIONS[1])));
}
break;
case 'KEEP_PROPORTIONS_ON_SMALLEST' :
if ($aImg[0] <= $aImg[1]) {
$width = $KEEP_PROPORTIONS[1];
$height = round ($aImg[1] / (round ($aImg[0]/$KEEP_PROPORTIONS[1])));
} else {
$height = $KEEP_PROPORTIONS[1];
$width = round ($aImg[0] / (round ($aImg[1]/$KEEP_PROPORTIONS[1])));
}
break;
case 'DO_NOT_KEEP_PROPORTIONS':
if ($iCmpt !== 3 || !is_int ($KEEP_PROPORTIONS[2])) {
return false;
}
$width = $KEEP_PROPORTIONS[1];
$height = $KEEP_PROPORTIONS[2];
break;
}
}
$getImg = create_function ('$fileName', 'return @imagecreatefrom'.$aTypes[$aImg[2]].'($fileName);');
$im = $getImg ($fileName);
$image_p = imagecreatetruecolor($width, $height);
imagecopyresampled($image_p, $im, 0, 0, 0, 0, $width, $height, $aImg[0], $aImg[1]);
$saveImg = create_function ('$img, $fileName', 'return @image'.$aTypes[$aImg[2]].'($img, $fichier_dossier.$fileName);');
if ($saveImg ($image_p, $fileName)) {
return true;
} else {
return false;
}
}
}
}
}
imageResize ('thumbnails','eoliennbnes.jpg', array ('DO_NOT_KEEP_PROPORTIONS', 100, 100));
Sa marche pour créé des vignettes mais je peu pas les enregistre ou je veux, j'ai essayer en rajoutent "$fichier_dossier." et sa marche pas.
merci en avance si vous trouvez mon erreure.