here is the function I use
function createthumb($name,$filename,$new_w,$new_h){
$system=explode('.',$name);
if (preg_match('jpg|jpeg',$system[3])) {
$src_img=imagecreatefromjpeg($name);
}
if (preg_match('png',$system[3])) {
$src_img=imagecreatefrompng($name);
}
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
if ($old_x > $old_y) {
$thumb_w=$new_w;
$thumb_h=$old_y*($new_h/$old_x);
}
if ($old_x < $old_y) {
$thumb_w=$old_x*($new_w/$old_y);
$thumb_h=$new_h;
}
if ($old_x == $old_y) {
$thumb_w=$new_w;
$thumb_h=$new_h;
}
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
if (preg_match("/png/",$system[3])) {
imagepng($dst_img,$filename);
} else {
imagejpeg($dst_img,$filename);
}
imagedestroy($dst_img);
imagedestroy($src_img);
}
the area where I am creating the image, its after the file is uploaded (hence $FILES) - basically saying, if upload successful then make a thumbnail
$thumbsdir = '../uploads/thumbs/tn_';
$thumbsfile = $thumbsdir . basename($_FILES['uploadedfile']['name']);
if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $uploadfile)) {
createthumb($uploadfile,$thumbsfile,100,100);
}
the upload is successful, it creates a thumbnail image with the correc name, in the correct directory, but it is a total black image.
any ideas?