Upload Script ist jetzt fertig...
Kann mir mal jemand sagen, ob ich da noch mehr Qualität aus den Bildern rausholen kann?
So richtig bin ich noch nicht zufrieden.
PHP Version ist 4.2.3
Hier mal ein Beispiel:
Original:
Resized:
Thumbnail:
Und hier der Code:
PHP-Code:
// Generiert Zufallsnamen für Bild
$zahl = md5 (uniqid (rand()));
$image_name = $zahl[0] . $zahl[5] . $zahl[2] . $zahl[8] .
$zahl[1] . $zahl[9] . $zahl[11] .$zahl[10].$zahl[13]. $zahl[7];
// Die Datei Endung Bestimmen
$pic_typ = $_FILES['picture_a']['type'];
$extension = "";
if($pic_typ=="image/gif") $extension = "gif";
if ($pic_typ=="image/jpg") $extension = "jpg";
if ($pic_typ=="image/jpeg") $extension = "jpg";
if ($pic_typ=="image/pjpeg") $extension = "jpg";
if ($pic_typ=="image/png") $extension = "png";
if ($pic_typ=="image/bmp") $extension = "bmp";
// Destination
$destination = "../ressourcen/upload/original/".$image_name.".".$extension;
// Bild verschieben
move_uploaded_file ($_FILES['picture_a']['tmp_name'], "$destination");
//Originalbild einlesen
$h_img= imagecreatefromjpeg($destination);
$width= imagesx($h_img);
$height= imagesy($h_img);
if(($width <= 640) && ($height <= 480)) {
echo "Keine Komprimierung....";
}
else {
// BILD KOMPRIMIEREN AUF 640 Breite oder 480 Höhe\\
// Bildgröße berechnen (640 = Breite, 480 = Höhe)
if( ($width/$height) > (1+(1/3)) ) {
$thb_x = 640;
$thb_y = ($thb_x/$width)*$height;
}
else if( ($width/$height) < (1+(1/3)) ) {
$thb_y = 480;
$thb_x = ($thb_y/$height)*$width;
}
else {
$thb_x = 640;
$thb_y = 480;
}
$h_thb = imagecreate($thb_x, $thb_y);
imagecopyresized(
$h_thb,
$h_img,
0,
0,
0,
0,
$thb_x,
$thb_y,
$width,
$height);
// In File speichern
$image_dir = "../ressourcen/upload/images/" . $image_name . ".jpg";
imagejpeg($h_thb, "$image_dir", 85);
}
// Thumbnail erstellen \\
// Bildgröße berechnen (100 = Breite, 75 = Höhe)
if( ($width/$height) > (1+(1/3)) ) {
$thb_x = 100;
$thb_y = ($thb_x/$width)*$height;
}
else if( ($width/$height) < (1+(1/3)) ) {
$thb_y = 75;
$thb_x = ($thb_y/$height)*$width;
}
else {
$thb_x = 100;
$thb_y = 75;
}
$h_thb = imagecreate(100, 75);
$f1f1f1 = ImageColorAllocate ($h_thb, 241, 241, 241);
imagefilledrectangle ($h_thb, 0, 0, 100, 75, $f1f1f1);
// Verkleinern
imagecopyresized(
$h_thb,
$h_img,
0,
0,
0,
0,
$thb_x,
$thb_y,
$width,
$height
);
// In File speichern
$thumb_dir = "../ressourcen/upload/thumbs/" . $image_name . ".jpg";
imagejpeg($h_thb, "$thumb_dir", 85);
Für Verbesserungsvorschläge bin ich jederzeit offen!
Lesezeichen