J'utilise img uploader sur mon ftp. Si l'image est grande à 1024x768, j'utilise un script pour redimensionner. Mais après redimensionnement perdre la qualité.Redimensionner l'image sans perte de qualité lorsque l'image est plus grande
code de uploader.php:
if(@move_uploaded_file($_FILES['myfile']['tmp_name'], "$upload_folder/" . $newname))
if($width>1024 || $height>768) {
require './image_resize.php';
echo (image_resize("$upload_folder/" . $newname, "$upload_folder/" . $newname, 1024, 768));
}
Code de bal image_resize.php:
<?php ini_set('memory_limit','500M');
function image_resize($src, $dst, $width, $height, $crop=0){
if(!($pic = @getimagesize($src)))
return false;
$w = $pic[0];
$h = $pic[1];
$type = substr($pic['mime'], 6);
$func = 'imagecreatefrom' . $type;
if(!function_exists($func))
return false;
$img = $func($src);
if($crop){
if($w < $width && $h < $height)
return false;
$ratio = max($width/$w, $height/$h);
$h = $height/$ratio;
$x = ($w - $width/$ratio)/2;
$w = $width/$ratio;
}
else{
if($w < $width && $h < $height)
return false;
$ratio = min($width/$w, $height/$h);
$width = $w * $ratio;
$height = $h * $ratio;
$x = 0;
}
$new = imagecreatetruecolor($width, $height);
if($type == "gif" || $type == "png"){
imagecolortransparent($new, imagecolorallocatealpha($new, 0, 0, 0, 127));
imagealphablending($new, false);
imagesavealpha($new, true);
}
imagecopyresampled($new, $img, 0, 0, $x, 0, $width, $height, $w, $h);
$save = 'image' . $type;
$save($new, $dst);
return true;
}
Il est impossible de réduire la taille sans perte de qualité :(
Le troisième paramètre dans 'image {type}()' est la qualité ... http: //php.net/manual/fr/function.imagejpeg.php – Rasclatt