Napisałem taki kod do generowania miniaturek z pliku jpg, gif oraz png
<?php
if($_FILES['img_main']['type']=="image/png" || $_FILES['img_main']['type']=="image/jpeg" || $_FILES['img_main']['type']=="image/gif") {
move_uploaded_file($_FILES['img_main']['tmp_name'], "../gal/".$tab['gallery_name']."/".$_FILES['img_main']['name']);
$img_path="../gal/".$tab['gallery_name']."/".$_FILES['img_main']['name'];
$thumb_path="../gal/".$tab['gallery_name']."/thumbs/".$_FILES['img_main']['name'];
$max_width=$max_height=100;
if($img_attr[0]>$img_attr[1]){
$scale = $img_attr[0] / $max_width;
}else{
$scale = $img_attr[1] / $max_height;
}
$w = floor($img_attr[0
]/$scale); $h = floor($img_attr[1
]/$scale); $thumb = imagecreatetruecolor($w,$h);
switch($_FILES['img_main']['type']) {
case "image/jpeg": {
imagecopyresampled($thumb, imagecreatefromjpeg($img_path), 0, 0, 0, 0, $w, $h, $img_attr[0], $img_attr[1]);
imagejpeg($thumb,$thumb_path,85);
break;
}
case "image/png": {
imagecopyresampled($thumb, imagecreatefrompng($img_path), 0, 0, 0, 0, $w, $h, $img_attr[0], $img_attr[1]);
//header('Content-type: image/png');
imagepng($thumb,$thumb_path,85);
break;
}
case "image/gif": {
imagecopyresampled($thumb, imagecreatefromgif($img_path), 0, 0, 0, 0, $w, $h, $img_attr[0], $img_attr[1]);
imagegif($thumb,$thumb_path,85);
break;
}
}
}
}
?>
Jednak przy próbie generacji miniaturki PNG zwraca błąd:
Kod
Warning: imagepng() [function.imagepng]: gd-png error: compression level must be 0 through 9 in D:\wamp\www\class\class_admin.php on line 289
Linia 289 to:
imagepng($thumb,$thumb_path,85);
Dodatkowo WampSerwer się "wykrzacza" podczas tej operacji. Czy ktoś ma na to jakiś pomysł?