Fabrizio
Fabrizio

Reputation: 13

why imagepng after resize create a black image?

i m trying to resize a image using code:

list($width,$height,$type,$attr)= getimagesize($_FILES['upload'.$num]['name']);
                $source = imagecreatefrompng($_FILES['upload'.$num]['name']);
                $thumb = imagecreatetruecolor(445,320);
                imagealphablending($thumb, false);
                imagesavealpha($thumb, true);  
                    imagecopyresampled($thumb,$source,0,0,0,0,445,320,$width,$height);
                imagepng($thumb,"../public/img/".$Nome,8);

but the output is always a black image..  anyone know why? 

Thanks

Upvotes: 1

Views: 384

Answers (1)

Peter
Peter

Reputation: 16943

$_FILES['upload'.$num]['name'] is just filename of uploaded like "flower.jpg" not full path to file.

$_FILES['upload'.$num]['tmp_name'] is real absolute path to real file uploaded on your server (somewhere in temp directory)


Your code should look like this:

list($width,$height,$type,$attr)= getimagesize($_FILES['upload'.$num]['tmp_name']);
$source = imagecreatefrompng($_FILES['upload'.$num]['tmp_name']);

Always try to debug your first. Use functions like print_r($_FILES), var_dump($_FILES) to debug your variables.

except issue with $_FILES variable, your code should works fine: Demo

Upvotes: 1

Related Questions