Ich benutze img Uploader auf meinem ftp. Wenn Bild auf 1024x768 groß ist benutze ich Skript für die Größenänderung. Aber nach der Größe verlieren Qualität.Bildgröße ändern, ohne Qualität zu verlieren, wenn das Bild größer ist
-Code von 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 prom 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;
}
Es ist unmöglich, die Größe zu reduzieren, ohne an Qualität einzubüßen :(
Der dritte Parameter in 'image {type}()' ist Qualität ... http: //php.net/manual/en/function.imagejpeg.php – Rasclatt