php imagecopyresized()制作全黑缩略图

So, I have this class that's half-working. Somehow I'm not being able to copy a re-sized sample of the uploaded image, only a black "square" with the "correct" dimensions (screw the dimensions, as long as the thumb comes up clear. one step at the time).

I'm sorry for the WOT but it's driving me cray-cray. Thanks in advance.

    <?php 
    class Upload {
#function from http://stackoverflow.com/a/10666106/587811
public function resize_values($origWidth,$origHeight,$maxWidth = 200,$maxHeight = 200){
    #check for longest side, we'll be seeing that to the max value above
    if($origHeight > $origWidth){ #if height is more than width
        $newWidth = ($maxHeight * $origWidth) / $origHeight;
        $retval = array(width => $newWidth, height => $maxHeight);
    }
    else{
        $newHeight= ($maxWidth * $origHeight) / $origWidth;
        $retval = array(width => $origWidth, height => $newHeight);
}
    return $retval;
}
public function image($picurl, $file, $path="images/uploaded/") {
    echo "function chamada!";
    if ($picurl) {
        $picFileName=rand(1,9999).$_SESSION['id'];
        $picExt=substr(strstr($picurl,'.'),1,3);
        $picExt=strtolower($picExt);
        $allowed = array("jpg","png","gif","bmp");
        if (in_array($picExt,$allowed)) {
            if (getimagesize($file)) {
                $picNewName=str_replace(" ","_",$picFileName.'.'.$picExt);
                $picWhereTo=$path.$picNewName;
                $copy=move_uploaded_file($file, $picWhereTo);       
                if ($copy) {

                    list($width, $height) = getimagesize($picWhereTo);
                    $size = $this->resize_values($width,$height,250,250);
                    $thumb = imagecreatetruecolor($size['width'],$size['height']);
    imagealphablending($thumb, false);
                    $source = imagecreatefromjpeg($picWhereTo);
                    imagecopyresized($thumb,$source,0,0,0,0,$size['width'],$size['height'],$width,$height);
                    $picNewName=$picFileName.'_thumb.'.$picExt;
                    imagejpeg($thumb,$path.$picNewName);

                    $picinfo['where']=$picWhereTo;
                    $picinfo['name']=$picNewName;
                    return $picinfo;
                }
                else return false;
            }
            else return false;
        }
        else return false;
    }
}
    }
    ?>

I've ran into a similar problem like this. This has to do with png's with transparency.

Give this a shot after you create $thumb using imagecreatetruecolor();

imagealphablending($thumb, false);

I'm not entirely certain this is the solution - but I think its along the right track. Your true color supports alpha blending - and it is blending in the background from the jpeg - and it might be confused by the lack of information.

If this doesn't work, please describe the exact image format you are uploading so we can try it out and see what happens.

Change your

$source = imagecreatefromjpeg($file);

to

$source = imagecreatefromjpeg($picWhereTo);

And this is how you call the function

$objoflclass->image($_FILES['img']['name'],$_FILES['img']['tmp_name'],'');

where $_FILES['img'] is the name of the image upload field and i believe from this u can understand what was the problem