Hy!
Ich verwende php, um jpegs upzuloaden und dann daraus thumbnails zu generieren. Leider haben die thumbnails eine katastrophale Qualität (s. attached jpg).
Bitte um Hilfe - danke!
Code:
...
function ResizeImageUsingGD($origimage, $newimage, $newwidth, $newheight) {
$size = GetImageSize($origimage);
$width = $size[0];
$height = $size[1];
if ($im = ImageCreateFromJPEG($origimage)) {
if ($newheight && ($width < $height)) {
$newwidth = ($newheight / $height) * $width;
} else {
$newheight = ($newwidth / $width) * $height;
}
$im2 = ImageCreateTrueColor($newwidth,$newheight);
ImageCopyResampled($im2,$im,0,0,0,0,$newwidth,$newheight,$width,$height);
if (ImageJpeg($im2, $newimage, $imagequality)) {
return true;
}
}
return false;
}
$ok = 0;
if ($action == "insertNew") {
$uploadfile = $uploaddir . basename($_FILES['image']['name']);
if (move_uploaded_file($_FILES['image']['tmp_name'], $uploadfile)) {
$rs = @mysql_query("SELECT max(id)+1 as id FROM ".$table."");
if ($rs) while ($line = @mysql_fetch_array($rs)) {
$maxid = $line["id"];
}
$origimage = $uploaddirpics.$maxid.".jpg";
copy($uploaddir.$file_name, $origimage);
unlink($uploaddir.$file_name);
$thumbimage = $uploaddirpics."thumbs/".$maxid.".jpg";
$thumb_exists = file_exists($thumbimage);
if (!$thumb_exists) {
ResizeImageUsingGD($origimage, $thumbimage, $reswidth, $resheight);
}
echo "Das Bild wurde erfolgreich auf den Server geladen.\n";
} else {
echo "Probleme beim Upload!\n";
}
...
PHP Version 4.3.2
gd-Info:
GD Support enabled
GD Version bundled (2.0.12 compatible)
GIF Read Support enabled
JPG Support enabled
PNG Support enabled
WBMP Support enabled
XBM Support enabled
Ich verwende php, um jpegs upzuloaden und dann daraus thumbnails zu generieren. Leider haben die thumbnails eine katastrophale Qualität (s. attached jpg).
Bitte um Hilfe - danke!
Code:
...
function ResizeImageUsingGD($origimage, $newimage, $newwidth, $newheight) {
$size = GetImageSize($origimage);
$width = $size[0];
$height = $size[1];
if ($im = ImageCreateFromJPEG($origimage)) {
if ($newheight && ($width < $height)) {
$newwidth = ($newheight / $height) * $width;
} else {
$newheight = ($newwidth / $width) * $height;
}
$im2 = ImageCreateTrueColor($newwidth,$newheight);
ImageCopyResampled($im2,$im,0,0,0,0,$newwidth,$newheight,$width,$height);
if (ImageJpeg($im2, $newimage, $imagequality)) {
return true;
}
}
return false;
}
$ok = 0;
if ($action == "insertNew") {
$uploadfile = $uploaddir . basename($_FILES['image']['name']);
if (move_uploaded_file($_FILES['image']['tmp_name'], $uploadfile)) {
$rs = @mysql_query("SELECT max(id)+1 as id FROM ".$table."");
if ($rs) while ($line = @mysql_fetch_array($rs)) {
$maxid = $line["id"];
}
$origimage = $uploaddirpics.$maxid.".jpg";
copy($uploaddir.$file_name, $origimage);
unlink($uploaddir.$file_name);
$thumbimage = $uploaddirpics."thumbs/".$maxid.".jpg";
$thumb_exists = file_exists($thumbimage);
if (!$thumb_exists) {
ResizeImageUsingGD($origimage, $thumbimage, $reswidth, $resheight);
}
echo "Das Bild wurde erfolgreich auf den Server geladen.\n";
} else {
echo "Probleme beim Upload!\n";
}
...
PHP Version 4.3.2
gd-Info:
GD Support enabled
GD Version bundled (2.0.12 compatible)
GIF Read Support enabled
JPG Support enabled
PNG Support enabled
WBMP Support enabled
XBM Support enabled
Kommentar