Hallo Leute,
ich habe ein Formular mit dem ich u.a. ein Bild hochladen bzw. verkleinern lassen will, aber ich bekomme immer nur ein schwarzes Bild. Der Resize hat aber geklappt. Auch klappt ein Upload wenn ich das Bild nur uploade und nicht verkleinere. Ich sehe einfach bei einem Script nicht den Fehler.
Hier mal mein Code:
Code:
$zielpfad = "../media/".$_POST['kategorie']."/";
$bilddatei = getimagesize($_FILES['bild']['tmp_name']);
$tmp_dateiname = $_FILES['bild']['tmp_name'];
$dateiname = strtolower($_POST['picnummer']);
$thumbdatei = strtolower($_POST['picnummer'])."_thumb";
if($bilddatei[2] != 0) {
switch($bilddatei[2]) {
case 1:
$dateiendung = ".gif";
$dateiname .= ".gif";
$thumbdatei .= ".gif";
break;
case 2:
$dateiendung = ".jpg";
$dateiname .= ".jpg";
$thumbdatei .= ".jpg";
break;
case 3:
$dateiendung = ".png";
$dateiname .= ".png";
$thumbdatei .= ".png";
break;
}
// prüfe ob Verzeichnis existiert
if(!file_exists($zielpfad)) {
mkdir($zielpfad);
}
// Thumbnail berechnen und erzeugen
$bildhoehe = 100;
$bildbreite = 340;
$tmp_bildbreite = $bilddatei[0];
$tmp_bildhoehe = $bilddatei[1];
$tmp_bildmime = $bilddatei['mime'];
if($tmp_bildbreite < $tmp_bildhoehe) {
$new_bildhoehe = ceil($tmp_bildhoehe * $bildbreite / $tmp_bildbreite);
$new_bildbreite = ceil($tmp_bildbreite * $bildhoehe / $tmp_bildhoehe);
} else {
$new_bildhoehe = ceil(($bildhoehe / $tmp_bildbreite)* $tmp_bildhoehe);
$new_bildbreite = $bildbreite;
}
$original = imagecreatefromjpeg($tmp_dateiname);
$thumb = imagecreatetruecolor($new_bildbreite, $new_bildhoehe);
imagecopyresampled($thumb, $original, 0, 0, 0, 0, $new_breite, $new_hoehe, $tmp_bildbreite, $tmp_bildhoehe);
imagejpeg($thumb, $zielpfad.$dateiname,100);
// temporäres Bild aus Speicher löschen
if(isset($thumb)) {
imagedestroy($thumb);
}
}