Problemer med GDlib og resizing.
Hej. Jeg har dette script som resizer mine billeder, men billeder bliver grynet når jeg kører den. :]createpic("../picture/".$_FILES[PictureFile][name],200,"../picture/".$filnavn[0]."_200px_width.jpg");
function createpic($image_source,$sizex,$output_file){
$image_source = "../picture/".$image_source;
$output_file = "../picture/".$output_file;
$backup_file = $output_file . "_backup.jpg";
copy($image_source,$backup_file);
$image_properties = getimagesize($backup_file);
if ($image_properties[0]<$sizex) {return(0);}
$ratio = $image_properties[1]/$image_properties[0];
$thumb_y = ($sizex*$ratio);
if (!$image_properties[2] == 2) {
return(0);
} else {
$src_image = imagecreatefromjpeg($backup_file);
$src_x = imagesx($src_image);
$src_y = imagesy($src_image);
if (($thumb_y == "0") && ($sizex == "0")) {
return(0);
} elseif ($thumb_y == "0") {
$scalex = $sizex/($src_x-1);
$thumb_y = $src_y*$scalex;
} elseif ($sizex == "0") {
$scaley = $thumb_y/($src_y-1);
$sizex = $src_x*$scaley;
}
$sizex = (int)($sizex);
$thumb_y = (int)($thumb_y);
$dest_image = imagecreatetruecolor($sizex, $thumb_y);
imagefill($dest_image,1,1,imagecolorallocate($dest_image, 255, 255, 255));
unlink($backup_file);
if (!imagecopyresized($dest_image, $src_image, 0, 0, 0, 0, $sizex, $thumb_y, $src_x, $src_y)) {
imagedestroy($src_image);
imagedestroy($dest_image);
return(0);
} else {
imagedestroy($src_image);
if (imagejpeg($dest_image,$output_file)) {
imagedestroy($dest_image);
return(1);
}
imagedestroy($dest_image);
}
return(0);
}
}